mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-15 20:25:18 +02:00
Fix being able to add an existing label
This commit is contained in:
parent
10af1f4104
commit
304d0b4d5d
21
assets/scripts/dist/choices.js
vendored
21
assets/scripts/dist/choices.js
vendored
|
@ -1300,7 +1300,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
|
|
||||||
if (this.config.addItems) {
|
if (this.config.addItems) {
|
||||||
var isUnique = !activeItems.some(function (item) {
|
var isUnique = !activeItems.some(function (item) {
|
||||||
return item.value === value.trim();
|
return item.value === value.trim() || item.label === value.trim();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.passedElement.type === 'select-multiple' || this.passedElement.type === 'text') {
|
if (this.passedElement.type === 'select-multiple' || this.passedElement.type === 'text') {
|
||||||
|
@ -1681,17 +1681,24 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
if (_this17.isTextElement) {
|
if (_this17.isTextElement) {
|
||||||
_this17._addItem(value);
|
_this17._addItem(value);
|
||||||
} else {
|
} else {
|
||||||
var existingChoice = void 0;
|
var matchingChoices = [];
|
||||||
|
var isUnique = void 0;
|
||||||
var duplicateItems = _this17.config.duplicateItems;
|
var duplicateItems = _this17.config.duplicateItems;
|
||||||
if (!duplicateItems) {
|
if (!duplicateItems) {
|
||||||
existingChoice = !_this17.store.getItems().filter(function (item) {
|
matchingChoices = _this17.store.getChoices().filter(function (choice) {
|
||||||
return item.value === value.trim();
|
return choice.label === value.trim();
|
||||||
|
});
|
||||||
|
isUnique = !_this17.store.getItemsFilteredByActive().some(function (item) {
|
||||||
|
return item.label === value.trim();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (duplicateItems) {
|
if (duplicateItems || matchingChoices.length === 0 && isUnique) {
|
||||||
_this17._addChoice(true, false, value, value);
|
_this17._addChoice(true, false, value, value);
|
||||||
} else {
|
}
|
||||||
_this17._addItem(existingChoice.value, existingChoice.label, existingChoice.id);
|
if (duplicateItems || isUnique) {
|
||||||
|
if (matchingChoices[0]) {
|
||||||
|
_this17._addItem(matchingChoices[0].value, matchingChoices[0].label, matchingChoices[0].id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_this17.containerOuter.focus();
|
_this17.containerOuter.focus();
|
||||||
}
|
}
|
||||||
|
|
4
assets/scripts/dist/choices.js.map
vendored
4
assets/scripts/dist/choices.js.map
vendored
File diff suppressed because one or more lines are too long
4
assets/scripts/dist/choices.min.js
vendored
4
assets/scripts/dist/choices.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1086,7 +1086,7 @@ class Choices {
|
||||||
let notice = isType('Function', this.config.addItemText) ? this.config.addItemText(value) : this.config.addItemText;
|
let notice = isType('Function', this.config.addItemText) ? this.config.addItemText(value) : this.config.addItemText;
|
||||||
|
|
||||||
if (this.config.addItems) {
|
if (this.config.addItems) {
|
||||||
const isUnique = !activeItems.some((item) => item.value === value.trim());
|
const isUnique = !activeItems.some((item) => (item.value === value.trim()) || (item.label === value.trim()));
|
||||||
|
|
||||||
if (this.passedElement.type === 'select-multiple' || this.passedElement.type === 'text') {
|
if (this.passedElement.type === 'select-multiple' || this.passedElement.type === 'text') {
|
||||||
if (this.config.maxItemCount > 0 && this.config.maxItemCount <= this.itemList.children.length) {
|
if (this.config.maxItemCount > 0 && this.config.maxItemCount <= this.itemList.children.length) {
|
||||||
|
@ -1390,17 +1390,28 @@ class Choices {
|
||||||
if (this.isTextElement) {
|
if (this.isTextElement) {
|
||||||
this._addItem(value);
|
this._addItem(value);
|
||||||
} else {
|
} else {
|
||||||
let existingChoice;
|
let matchingChoices = [];
|
||||||
|
let isUnique;
|
||||||
const duplicateItems = this.config.duplicateItems;
|
const duplicateItems = this.config.duplicateItems;
|
||||||
if (!duplicateItems) {
|
if (!duplicateItems) {
|
||||||
existingChoice = !this.store
|
matchingChoices = this.store
|
||||||
.getItems()
|
.getChoices()
|
||||||
.filter((item) => item.value === value.trim());
|
.filter((choice) => choice.label === value.trim());
|
||||||
|
isUnique = !this.store
|
||||||
|
.getItemsFilteredByActive()
|
||||||
|
.some((item) => item.label === value.trim());
|
||||||
}
|
}
|
||||||
if (duplicateItems) {
|
if (duplicateItems || (matchingChoices.length === 0 && isUnique)) {
|
||||||
this._addChoice(true, false, value, value);
|
this._addChoice(true, false, value, value);
|
||||||
} else {
|
}
|
||||||
this._addItem(existingChoice.value, existingChoice.label, existingChoice.id);
|
if (duplicateItems || isUnique) {
|
||||||
|
if (matchingChoices[0]) {
|
||||||
|
this._addItem(
|
||||||
|
matchingChoices[0].value,
|
||||||
|
matchingChoices[0].label,
|
||||||
|
matchingChoices[0].id
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.containerOuter.focus();
|
this.containerOuter.focus();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue