forked from mirror/Part-DB.Part-DB-server
Disable create option for input selects if an entity with this name already exists
This commit is contained in:
parent
9502f30e1b
commit
d7c741c652
1 changed files with 26 additions and 0 deletions
|
@ -48,6 +48,7 @@ export default class extends Controller {
|
||||||
selectOnTab: true,
|
selectOnTab: true,
|
||||||
maxOptions: null,
|
maxOptions: null,
|
||||||
create: allowAdd ? this.createItem.bind(this) : false,
|
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)
|
// This three options allow us to paste element names with commas: (see issue #538)
|
||||||
maxItems: 1,
|
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() {
|
updateValidity() {
|
||||||
//Mark this input as invalid, if the selected option is disabled
|
//Mark this input as invalid, if the selected option is disabled
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue