diff --git a/assets/controllers/elements/structural_entity_select_controller.js b/assets/controllers/elements/structural_entity_select_controller.js index 6d436676..a1114a97 100644 --- a/assets/controllers/elements/structural_entity_select_controller.js +++ b/assets/controllers/elements/structural_entity_select_controller.js @@ -48,6 +48,7 @@ export default class extends Controller { selectOnTab: true, maxOptions: null, create: allowAdd ? this.createItem.bind(this) : false, + createFilter: this.createFilter.bind(this), // This three options allow us to paste element names with commas: (see issue #538) maxItems: 1, @@ -128,6 +129,31 @@ export default class extends Controller { }); } + createFilter(input) { + + //Normalize the input (replace spacing around arrows) + if (input.includes("->")) { + const inputs = input.split("->"); + inputs.forEach((value, index) => { + inputs[index] = value.trim(); + }); + input = inputs.join("->"); + } else { + input = input.trim(); + } + + const options = this._tomSelect.options; + //Iterate over all options and check if the input is already present + for (let index in options) { + const option = options[index]; + if (option.path === input) { + return false; + } + } + + return true; + } + updateValidity() { //Mark this input as invalid, if the selected option is disabled