Skip to content

Commit 9502f30

Browse files
committed
Add cllear button to entity select type
1 parent 7286c4b commit 9502f30

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

assets/controllers/elements/structural_entity_select_controller.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import {Controller} from "@hotwired/stimulus";
2424

2525
import {trans, ENTITY_SELECT_GROUP_NEW_NOT_ADDED_TO_DB} from '../../translator.js'
2626

27+
import TomSelect_autoselect_typed from '../../tomselect/autoselect_typed/autoselect_typed'
28+
TomSelect.define('autoselect_typed', TomSelect_autoselect_typed)
29+
2730
export default class extends Controller {
2831
_tomSelect;
2932

@@ -37,6 +40,9 @@ export default class extends Controller {
3740
const allowAdd = this.element.getAttribute("data-allow-add") === "true";
3841
const addHint = this.element.getAttribute("data-add-hint") ?? "";
3942

43+
44+
45+
4046
let settings = {
4147
allowEmptyOption: true,
4248
selectOnTab: true,
@@ -81,8 +87,17 @@ export default class extends Controller {
8187
//Add callbacks to update validity
8288
onInitialize: this.updateValidity.bind(this),
8389
onChange: this.updateValidity.bind(this),
90+
91+
plugins: {
92+
"autoselect_typed": {},
93+
}
8494
};
8595

96+
//Add clear button plugin, if an empty option is present
97+
if (this.element.querySelector("option[value='']") !== null) {
98+
settings.plugins["clear_button"] = {};
99+
}
100+
86101
this._tomSelect = new TomSelect(this.element, settings);
87102
//Do not do a sync here as this breaks the initial rendering of the empty option
88103
//this._tomSelect.sync();

0 commit comments

Comments
 (0)