Skip to content

Commit

Permalink
Disable create option for input selects if an entity with this name a…
Browse files Browse the repository at this point in the history
…lready exists
  • Loading branch information
jbtronics committed Feb 16, 2025
1 parent 9502f30 commit d7c741c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions assets/controllers/elements/structural_entity_select_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d7c741c

Please sign in to comment.