@@ -24,6 +24,9 @@ import {Controller} from "@hotwired/stimulus";
2424
2525import { 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+
2730export 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