Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added clearable method to select form field #2581

Open
wants to merge 4 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions frontend/js/components/VSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
:searchable="searchable"
:selectable="selectable"
:clearSearchOnSelect="clearSearchOnSelect"
:clearable="clearable"
:label="optionsLabel"
:taggable="taggable"
:pushTags="pushTags"
Expand Down Expand Up @@ -81,6 +82,10 @@
type: Boolean,
default: false
},
clearable: {
type: Boolean,
default: false
},
selectable: {
type: Function,
default: option => option.selectable ?? true,
Expand Down
5 changes: 0 additions & 5 deletions frontend/js/components/VSelect/ExtendedVSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@
mutableValue: this.value
}
},
computed: {
showClearButton () {
return false
}
},
methods: {
/**
* Delete the value on Delete keypress when there is no
Expand Down
15 changes: 10 additions & 5 deletions frontend/scss/vendor/_vselect.scss
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ $multiSelectHeight: 45px;
padding-left: 0;
}

.vs__clear {
margin-right: 35px;
margin-top: 2px;
}

.vs__selected-options {
padding: 0 30px 0 15px;
}
Expand Down Expand Up @@ -406,15 +411,15 @@ $multiSelectHeight: 45px;

.close,
.vs__deselect {
top:2px;
right:2px;
background-color:transparent;
top: 11px;
right: 2px;
background-color: transparent;
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMCIgaGVpZ2h0PSIxMCIgdmlld0JveD0iMCAwIDEwIDEwIj48cGF0aCBmaWxsPSJub25lIiBzdHJva2U9IiNhNmE2YTYiIGQ9Ik0yIDJsNiA2TTggMkwyIDgiLz48L3N2Zz4=);
color:$color__fborder--hover;
color: $color__fborder--hover;

span,
svg {
display:none
display: none
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/Services/Forms/Fields/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use A17\Twill\Services\Forms\Fields\Traits\HasPlaceholder;
use A17\Twill\Services\Forms\Fields\Traits\IsTranslatable;
use A17\Twill\Services\Forms\Fields\Traits\Unpackable;
use A17\Twill\Services\Forms\Option;
use A17\Twill\Services\Forms\Options;

class Select extends BaseFormField
{
Expand All @@ -15,6 +17,7 @@ class Select extends BaseFormField
use Unpackable;

protected bool $searchable = false;
protected bool $clearable = false;

public static function make(): static
{
Expand All @@ -33,4 +36,14 @@ public function searchable(bool $searchable = true): static

return $this;
}

/**
* If the field should be clearable.
*/
public function clearable(bool $clearable = true): static
{
$this->clearable = $clearable;

return $this;
}
}
1 change: 1 addition & 0 deletions src/View/Components/Fields/FieldWithOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct(
public bool $unpack = false,
public int $columns = 0,
public bool $searchable = false,
public bool $clearable = false,
public ?string $placeholder = null,
public bool $addNew = false,
public ?string $moduleName = null,
Expand Down
2 changes: 2 additions & 0 deletions src/View/Components/Fields/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __construct(
bool $unpack = false,
int $columns = 0,
bool $searchable = false,
bool $clearable = false,
?string $placeholder = '',
bool $addNew = false,
?string $moduleName = null,
Expand All @@ -51,6 +52,7 @@ public function __construct(
$unpack,
$columns,
$searchable,
$clearable,
$placeholder,
$addNew,
$moduleName,
Expand Down
1 change: 1 addition & 0 deletions views/partials/form/_select.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
@if ($addNew) add-new='{{ $storeUrl }}' @elseif ($note) note='{{ $note }}' @endif
:has-default-store="true"
@if ($searchable) :searchable="true" @endif
@if ($clearable) :clearable="true" @endif
size="large"
in-store="inputValue"
>
Expand Down
Loading