Skip to content

Commit 60af476

Browse files
zeezo887ifox
andauthored
feat: added clearable method to select form field (#2581)
--------- Co-authored-by: Quentin Renard <quentin@area17.com>
1 parent 042c87e commit 60af476

File tree

7 files changed

+29
-7
lines changed

7 files changed

+29
-7
lines changed

frontend/js/components/VSelect.vue

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
:searchable="searchable"
1414
:selectable="selectable"
1515
:clearSearchOnSelect="clearSearchOnSelect"
16+
:clearable="clearable"
1617
:label="optionsLabel"
1718
:taggable="taggable"
1819
:pushTags="pushTags"
@@ -81,6 +82,10 @@
8182
type: Boolean,
8283
default: false
8384
},
85+
clearable: {
86+
type: Boolean,
87+
default: false
88+
},
8489
selectable: {
8590
type: Function,
8691
default: option => option.selectable ?? true,

frontend/js/components/VSelect/ExtendedVSelect.vue

-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838
mutableValue: this.value
3939
}
4040
},
41-
computed: {
42-
showClearButton () {
43-
return false
44-
}
45-
},
4641
methods: {
4742
/**
4843
* Delete the value on Delete keypress when there is no

frontend/scss/vendor/_vselect.scss

+7-2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ $multiSelectHeight: 45px;
132132
padding-left: 0;
133133
}
134134

135+
.vs__clear {
136+
margin-right: 35px;
137+
margin-top: 2px;
138+
}
139+
135140
.vs__selected-options {
136141
padding: 0 30px 0 15px;
137142
}
@@ -414,11 +419,11 @@ $multiSelectHeight: 45px;
414419
transform: none;
415420
background-color:transparent;
416421
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMCIgaGVpZ2h0PSIxMCIgdmlld0JveD0iMCAwIDEwIDEwIj48cGF0aCBmaWxsPSJub25lIiBzdHJva2U9IiNhNmE2YTYiIGQ9Ik0yIDJsNiA2TTggMkwyIDgiLz48L3N2Zz4=);
417-
color:$color__fborder--hover;
422+
color: $color__fborder--hover;
418423

419424
span,
420425
svg {
421-
display:none
426+
display: none
422427
}
423428
}
424429
}

src/Services/Forms/Fields/Select.php

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use A17\Twill\Services\Forms\Fields\Traits\HasPlaceholder;
77
use A17\Twill\Services\Forms\Fields\Traits\IsTranslatable;
88
use A17\Twill\Services\Forms\Fields\Traits\Unpackable;
9+
use A17\Twill\Services\Forms\Option;
10+
use A17\Twill\Services\Forms\Options;
911

1012
class Select extends BaseFormField
1113
{
@@ -15,6 +17,7 @@ class Select extends BaseFormField
1517
use Unpackable;
1618

1719
protected bool $searchable = false;
20+
protected bool $clearable = false;
1821

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

3437
return $this;
3538
}
39+
40+
/**
41+
* If the field should be clearable.
42+
*/
43+
public function clearable(bool $clearable = true): static
44+
{
45+
$this->clearable = $clearable;
46+
47+
return $this;
48+
}
3649
}

src/View/Components/Fields/FieldWithOptions.php

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function __construct(
3030
public bool $unpack = false,
3131
public int $columns = 0,
3232
public bool $searchable = false,
33+
public bool $clearable = false,
3334
public ?string $placeholder = null,
3435
public bool $addNew = false,
3536
public ?string $moduleName = null,

src/View/Components/Fields/Select.php

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function __construct(
2626
bool $unpack = false,
2727
int $columns = 0,
2828
bool $searchable = false,
29+
bool $clearable = false,
2930
?string $placeholder = '',
3031
bool $addNew = false,
3132
?string $moduleName = null,
@@ -51,6 +52,7 @@ public function __construct(
5152
$unpack,
5253
$columns,
5354
$searchable,
55+
$clearable,
5456
$placeholder,
5557
$addNew,
5658
$moduleName,

views/partials/form/_select.blade.php

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
@if ($addNew) add-new='{{ $storeUrl }}' @elseif ($note) note='{{ $note }}' @endif
6464
:has-default-store="true"
6565
@if ($searchable) :searchable="true" @endif
66+
@if ($clearable) :clearable="true" @endif
6667
size="large"
6768
in-store="inputValue"
6869
>

0 commit comments

Comments
 (0)