mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-11 01:56:34 +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) {
|
||||
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') {
|
||||
|
@ -1681,17 +1681,24 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
if (_this17.isTextElement) {
|
||||
_this17._addItem(value);
|
||||
} else {
|
||||
var existingChoice = void 0;
|
||||
var matchingChoices = [];
|
||||
var isUnique = void 0;
|
||||
var duplicateItems = _this17.config.duplicateItems;
|
||||
if (!duplicateItems) {
|
||||
existingChoice = !_this17.store.getItems().filter(function (item) {
|
||||
return item.value === value.trim();
|
||||
matchingChoices = _this17.store.getChoices().filter(function (choice) {
|
||||
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);
|
||||
} 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();
|
||||
}
|
||||
|
|
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;
|
||||
|
||||
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.config.maxItemCount > 0 && this.config.maxItemCount <= this.itemList.children.length) {
|
||||
|
@ -1390,17 +1390,28 @@ class Choices {
|
|||
if (this.isTextElement) {
|
||||
this._addItem(value);
|
||||
} else {
|
||||
let existingChoice;
|
||||
let matchingChoices = [];
|
||||
let isUnique;
|
||||
const duplicateItems = this.config.duplicateItems;
|
||||
if (!duplicateItems) {
|
||||
existingChoice = !this.store
|
||||
.getItems()
|
||||
.filter((item) => item.value === value.trim());
|
||||
matchingChoices = this.store
|
||||
.getChoices()
|
||||
.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);
|
||||
} 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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue