Skip to content

Commit

Permalink
feat: added clearable method to select form field (#2581)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Quentin Renard <[email protected]>
  • Loading branch information
zeezo887 and ifox authored Oct 15, 2024
1 parent 042c87e commit 60af476
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
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
9 changes: 7 additions & 2 deletions frontend/scss/vendor/_vselect.scss
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,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 @@ -414,11 +419,11 @@ $multiSelectHeight: 45px;
transform: none;
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

0 comments on commit 60af476

Please sign in to comment.