File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
assets/controllers/elements Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ export default class extends Controller {
4848 selectOnTab : true ,
4949 maxOptions : null ,
5050 create : allowAdd ? this . createItem . bind ( this ) : false ,
51+ createFilter : this . createFilter . bind ( this ) ,
5152
5253 // This three options allow us to paste element names with commas: (see issue #538)
5354 maxItems : 1 ,
@@ -128,6 +129,31 @@ export default class extends Controller {
128129 } ) ;
129130 }
130131
132+ createFilter ( input ) {
133+
134+ //Normalize the input (replace spacing around arrows)
135+ if ( input . includes ( "->" ) ) {
136+ const inputs = input . split ( "->" ) ;
137+ inputs . forEach ( ( value , index ) => {
138+ inputs [ index ] = value . trim ( ) ;
139+ } ) ;
140+ input = inputs . join ( "->" ) ;
141+ } else {
142+ input = input . trim ( ) ;
143+ }
144+
145+ const options = this . _tomSelect . options ;
146+ //Iterate over all options and check if the input is already present
147+ for ( let index in options ) {
148+ const option = options [ index ] ;
149+ if ( option . path === input ) {
150+ return false ;
151+ }
152+ }
153+
154+ return true ;
155+ }
156+
131157
132158 updateValidity ( ) {
133159 //Mark this input as invalid, if the selected option is disabled
You can’t perform that action at this time.
0 commit comments