This commit is contained in:
Xon 2025-02-26 13:10:52 +00:00
commit 6733a6a69a
10 changed files with 127 additions and 55 deletions

View file

@ -1,4 +1,4 @@
/*! choices.js v11.0.4 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ /*! choices.js v11.0.5 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
(function (global, factory) { (function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@ -3769,13 +3769,14 @@
* }], 'value', 'label', false); * }], 'value', 'label', false);
* ``` * ```
*/ */
Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices, clearSearchFlag) { Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices, clearSearchFlag, replaceItems) {
var _this = this; var _this = this;
if (choicesArrayOrFetcher === void 0) { choicesArrayOrFetcher = []; } if (choicesArrayOrFetcher === void 0) { choicesArrayOrFetcher = []; }
if (value === void 0) { value = 'value'; } if (value === void 0) { value = 'value'; }
if (label === void 0) { label = 'label'; } if (label === void 0) { label = 'label'; }
if (replaceChoices === void 0) { replaceChoices = false; } if (replaceChoices === void 0) { replaceChoices = false; }
if (clearSearchFlag === void 0) { clearSearchFlag = true; } if (clearSearchFlag === void 0) { clearSearchFlag = true; }
if (replaceItems === void 0) { replaceItems = false; }
if (!this.initialisedOK) { if (!this.initialisedOK) {
this._warnChoicesInitFailed('setChoices'); this._warnChoicesInitFailed('setChoices');
return this; return this;
@ -3786,10 +3787,6 @@
if (typeof value !== 'string' || !value) { if (typeof value !== 'string' || !value) {
throw new TypeError("value parameter must be a name of 'value' field in passed objects"); throw new TypeError("value parameter must be a name of 'value' field in passed objects");
} }
// Clear choices if needed
if (replaceChoices) {
this.clearChoices();
}
if (typeof choicesArrayOrFetcher === 'function') { if (typeof choicesArrayOrFetcher === 'function') {
// it's a choices fetcher function // it's a choices fetcher function
var fetcher_1 = choicesArrayOrFetcher(this); var fetcher_1 = choicesArrayOrFetcher(this);
@ -3799,7 +3796,9 @@
return new Promise(function (resolve) { return requestAnimationFrame(resolve); }) return new Promise(function (resolve) { return requestAnimationFrame(resolve); })
.then(function () { return _this._handleLoadingState(true); }) .then(function () { return _this._handleLoadingState(true); })
.then(function () { return fetcher_1; }) .then(function () { return fetcher_1; })
.then(function (data) { return _this.setChoices(data, value, label, replaceChoices); }) .then(function (data) {
return _this.setChoices(data, value, label, replaceChoices, clearSearchFlag, replaceItems);
})
.catch(function (err) { .catch(function (err) {
if (!_this.config.silent) { if (!_this.config.silent) {
console.error(err); console.error(err);
@ -3823,6 +3822,16 @@
if (clearSearchFlag) { if (clearSearchFlag) {
_this._isSearching = false; _this._isSearching = false;
} }
var items = {};
if (!replaceItems) {
_this._store.items.forEach(function (item) {
items[item.value] = item;
});
}
// Clear choices if needed
if (replaceChoices) {
_this.clearChoices();
}
var isDefaultValue = value === 'value'; var isDefaultValue = value === 'value';
var isDefaultLabel = label === 'label'; var isDefaultLabel = label === 'label';
choicesArrayOrFetcher.forEach(function (groupOrChoice) { choicesArrayOrFetcher.forEach(function (groupOrChoice) {
@ -3839,6 +3848,9 @@
choice = __assign(__assign({}, choice), { value: choice[value], label: choice[label] }); choice = __assign(__assign({}, choice), { value: choice[value], label: choice[label] });
} }
var choiceFull = mapInputToChoice(choice, false); var choiceFull = mapInputToChoice(choice, false);
if (!replaceItems && choiceFull.value in items) {
choiceFull.selected = true;
}
_this._addChoice(choiceFull); _this._addChoice(choiceFull);
if (choiceFull.placeholder && !_this._hasNonChoicePlaceholder) { if (choiceFull.placeholder && !_this._hasNonChoicePlaceholder) {
_this._placeholderValue = unwrapStringForEscaped(choiceFull.label); _this._placeholderValue = unwrapStringForEscaped(choiceFull.label);
@ -5206,7 +5218,7 @@
throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it")); throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it"));
} }
}; };
Choices.version = '11.0.4'; Choices.version = '11.0.5';
return Choices; return Choices;
}()); }());

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
/*! choices.js v11.0.4 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ /*! choices.js v11.0.5 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/****************************************************************************** /******************************************************************************
Copyright (c) Microsoft Corporation. Copyright (c) Microsoft Corporation.
@ -3763,13 +3763,14 @@ var Choices = /** @class */ (function () {
* }], 'value', 'label', false); * }], 'value', 'label', false);
* ``` * ```
*/ */
Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices, clearSearchFlag) { Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices, clearSearchFlag, replaceItems) {
var _this = this; var _this = this;
if (choicesArrayOrFetcher === void 0) { choicesArrayOrFetcher = []; } if (choicesArrayOrFetcher === void 0) { choicesArrayOrFetcher = []; }
if (value === void 0) { value = 'value'; } if (value === void 0) { value = 'value'; }
if (label === void 0) { label = 'label'; } if (label === void 0) { label = 'label'; }
if (replaceChoices === void 0) { replaceChoices = false; } if (replaceChoices === void 0) { replaceChoices = false; }
if (clearSearchFlag === void 0) { clearSearchFlag = true; } if (clearSearchFlag === void 0) { clearSearchFlag = true; }
if (replaceItems === void 0) { replaceItems = false; }
if (!this.initialisedOK) { if (!this.initialisedOK) {
this._warnChoicesInitFailed('setChoices'); this._warnChoicesInitFailed('setChoices');
return this; return this;
@ -3780,10 +3781,6 @@ var Choices = /** @class */ (function () {
if (typeof value !== 'string' || !value) { if (typeof value !== 'string' || !value) {
throw new TypeError("value parameter must be a name of 'value' field in passed objects"); throw new TypeError("value parameter must be a name of 'value' field in passed objects");
} }
// Clear choices if needed
if (replaceChoices) {
this.clearChoices();
}
if (typeof choicesArrayOrFetcher === 'function') { if (typeof choicesArrayOrFetcher === 'function') {
// it's a choices fetcher function // it's a choices fetcher function
var fetcher_1 = choicesArrayOrFetcher(this); var fetcher_1 = choicesArrayOrFetcher(this);
@ -3793,7 +3790,9 @@ var Choices = /** @class */ (function () {
return new Promise(function (resolve) { return requestAnimationFrame(resolve); }) return new Promise(function (resolve) { return requestAnimationFrame(resolve); })
.then(function () { return _this._handleLoadingState(true); }) .then(function () { return _this._handleLoadingState(true); })
.then(function () { return fetcher_1; }) .then(function () { return fetcher_1; })
.then(function (data) { return _this.setChoices(data, value, label, replaceChoices); }) .then(function (data) {
return _this.setChoices(data, value, label, replaceChoices, clearSearchFlag, replaceItems);
})
.catch(function (err) { .catch(function (err) {
if (!_this.config.silent) { if (!_this.config.silent) {
console.error(err); console.error(err);
@ -3817,6 +3816,16 @@ var Choices = /** @class */ (function () {
if (clearSearchFlag) { if (clearSearchFlag) {
_this._isSearching = false; _this._isSearching = false;
} }
var items = {};
if (!replaceItems) {
_this._store.items.forEach(function (item) {
items[item.value] = item;
});
}
// Clear choices if needed
if (replaceChoices) {
_this.clearChoices();
}
var isDefaultValue = value === 'value'; var isDefaultValue = value === 'value';
var isDefaultLabel = label === 'label'; var isDefaultLabel = label === 'label';
choicesArrayOrFetcher.forEach(function (groupOrChoice) { choicesArrayOrFetcher.forEach(function (groupOrChoice) {
@ -3833,6 +3842,9 @@ var Choices = /** @class */ (function () {
choice = __assign(__assign({}, choice), { value: choice[value], label: choice[label] }); choice = __assign(__assign({}, choice), { value: choice[value], label: choice[label] });
} }
var choiceFull = mapInputToChoice(choice, false); var choiceFull = mapInputToChoice(choice, false);
if (!replaceItems && choiceFull.value in items) {
choiceFull.selected = true;
}
_this._addChoice(choiceFull); _this._addChoice(choiceFull);
if (choiceFull.placeholder && !_this._hasNonChoicePlaceholder) { if (choiceFull.placeholder && !_this._hasNonChoicePlaceholder) {
_this._placeholderValue = unwrapStringForEscaped(choiceFull.label); _this._placeholderValue = unwrapStringForEscaped(choiceFull.label);
@ -5200,7 +5212,7 @@ var Choices = /** @class */ (function () {
throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it")); throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it"));
} }
}; };
Choices.version = '11.0.4'; Choices.version = '11.0.5';
return Choices; return Choices;
}()); }());

View file

@ -1,4 +1,4 @@
/*! choices.js v11.0.4 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ /*! choices.js v11.0.5 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
(function (global, factory) { (function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@ -3287,13 +3287,14 @@
* }], 'value', 'label', false); * }], 'value', 'label', false);
* ``` * ```
*/ */
Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices, clearSearchFlag) { Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices, clearSearchFlag, replaceItems) {
var _this = this; var _this = this;
if (choicesArrayOrFetcher === void 0) { choicesArrayOrFetcher = []; } if (choicesArrayOrFetcher === void 0) { choicesArrayOrFetcher = []; }
if (value === void 0) { value = 'value'; } if (value === void 0) { value = 'value'; }
if (label === void 0) { label = 'label'; } if (label === void 0) { label = 'label'; }
if (replaceChoices === void 0) { replaceChoices = false; } if (replaceChoices === void 0) { replaceChoices = false; }
if (clearSearchFlag === void 0) { clearSearchFlag = true; } if (clearSearchFlag === void 0) { clearSearchFlag = true; }
if (replaceItems === void 0) { replaceItems = false; }
if (!this.initialisedOK) { if (!this.initialisedOK) {
this._warnChoicesInitFailed('setChoices'); this._warnChoicesInitFailed('setChoices');
return this; return this;
@ -3304,10 +3305,6 @@
if (typeof value !== 'string' || !value) { if (typeof value !== 'string' || !value) {
throw new TypeError("value parameter must be a name of 'value' field in passed objects"); throw new TypeError("value parameter must be a name of 'value' field in passed objects");
} }
// Clear choices if needed
if (replaceChoices) {
this.clearChoices();
}
if (typeof choicesArrayOrFetcher === 'function') { if (typeof choicesArrayOrFetcher === 'function') {
// it's a choices fetcher function // it's a choices fetcher function
var fetcher_1 = choicesArrayOrFetcher(this); var fetcher_1 = choicesArrayOrFetcher(this);
@ -3317,7 +3314,9 @@
return new Promise(function (resolve) { return requestAnimationFrame(resolve); }) return new Promise(function (resolve) { return requestAnimationFrame(resolve); })
.then(function () { return _this._handleLoadingState(true); }) .then(function () { return _this._handleLoadingState(true); })
.then(function () { return fetcher_1; }) .then(function () { return fetcher_1; })
.then(function (data) { return _this.setChoices(data, value, label, replaceChoices); }) .then(function (data) {
return _this.setChoices(data, value, label, replaceChoices, clearSearchFlag, replaceItems);
})
.catch(function (err) { .catch(function (err) {
if (!_this.config.silent) { if (!_this.config.silent) {
console.error(err); console.error(err);
@ -3341,6 +3340,16 @@
if (clearSearchFlag) { if (clearSearchFlag) {
_this._isSearching = false; _this._isSearching = false;
} }
var items = {};
if (!replaceItems) {
_this._store.items.forEach(function (item) {
items[item.value] = item;
});
}
// Clear choices if needed
if (replaceChoices) {
_this.clearChoices();
}
var isDefaultValue = value === 'value'; var isDefaultValue = value === 'value';
var isDefaultLabel = label === 'label'; var isDefaultLabel = label === 'label';
choicesArrayOrFetcher.forEach(function (groupOrChoice) { choicesArrayOrFetcher.forEach(function (groupOrChoice) {
@ -3357,6 +3366,9 @@
choice = __assign(__assign({}, choice), { value: choice[value], label: choice[label] }); choice = __assign(__assign({}, choice), { value: choice[value], label: choice[label] });
} }
var choiceFull = mapInputToChoice(choice, false); var choiceFull = mapInputToChoice(choice, false);
if (!replaceItems && choiceFull.value in items) {
choiceFull.selected = true;
}
_this._addChoice(choiceFull); _this._addChoice(choiceFull);
if (choiceFull.placeholder && !_this._hasNonChoicePlaceholder) { if (choiceFull.placeholder && !_this._hasNonChoicePlaceholder) {
_this._placeholderValue = unwrapStringForEscaped(choiceFull.label); _this._placeholderValue = unwrapStringForEscaped(choiceFull.label);
@ -4724,7 +4736,7 @@
throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it")); throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it"));
} }
}; };
Choices.version = '11.0.4'; Choices.version = '11.0.5';
return Choices; return Choices;
}()); }());

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
/*! choices.js v11.0.4 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ /*! choices.js v11.0.5 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/****************************************************************************** /******************************************************************************
Copyright (c) Microsoft Corporation. Copyright (c) Microsoft Corporation.
@ -3281,13 +3281,14 @@ var Choices = /** @class */ (function () {
* }], 'value', 'label', false); * }], 'value', 'label', false);
* ``` * ```
*/ */
Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices, clearSearchFlag) { Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices, clearSearchFlag, replaceItems) {
var _this = this; var _this = this;
if (choicesArrayOrFetcher === void 0) { choicesArrayOrFetcher = []; } if (choicesArrayOrFetcher === void 0) { choicesArrayOrFetcher = []; }
if (value === void 0) { value = 'value'; } if (value === void 0) { value = 'value'; }
if (label === void 0) { label = 'label'; } if (label === void 0) { label = 'label'; }
if (replaceChoices === void 0) { replaceChoices = false; } if (replaceChoices === void 0) { replaceChoices = false; }
if (clearSearchFlag === void 0) { clearSearchFlag = true; } if (clearSearchFlag === void 0) { clearSearchFlag = true; }
if (replaceItems === void 0) { replaceItems = false; }
if (!this.initialisedOK) { if (!this.initialisedOK) {
this._warnChoicesInitFailed('setChoices'); this._warnChoicesInitFailed('setChoices');
return this; return this;
@ -3298,10 +3299,6 @@ var Choices = /** @class */ (function () {
if (typeof value !== 'string' || !value) { if (typeof value !== 'string' || !value) {
throw new TypeError("value parameter must be a name of 'value' field in passed objects"); throw new TypeError("value parameter must be a name of 'value' field in passed objects");
} }
// Clear choices if needed
if (replaceChoices) {
this.clearChoices();
}
if (typeof choicesArrayOrFetcher === 'function') { if (typeof choicesArrayOrFetcher === 'function') {
// it's a choices fetcher function // it's a choices fetcher function
var fetcher_1 = choicesArrayOrFetcher(this); var fetcher_1 = choicesArrayOrFetcher(this);
@ -3311,7 +3308,9 @@ var Choices = /** @class */ (function () {
return new Promise(function (resolve) { return requestAnimationFrame(resolve); }) return new Promise(function (resolve) { return requestAnimationFrame(resolve); })
.then(function () { return _this._handleLoadingState(true); }) .then(function () { return _this._handleLoadingState(true); })
.then(function () { return fetcher_1; }) .then(function () { return fetcher_1; })
.then(function (data) { return _this.setChoices(data, value, label, replaceChoices); }) .then(function (data) {
return _this.setChoices(data, value, label, replaceChoices, clearSearchFlag, replaceItems);
})
.catch(function (err) { .catch(function (err) {
if (!_this.config.silent) { if (!_this.config.silent) {
console.error(err); console.error(err);
@ -3335,6 +3334,16 @@ var Choices = /** @class */ (function () {
if (clearSearchFlag) { if (clearSearchFlag) {
_this._isSearching = false; _this._isSearching = false;
} }
var items = {};
if (!replaceItems) {
_this._store.items.forEach(function (item) {
items[item.value] = item;
});
}
// Clear choices if needed
if (replaceChoices) {
_this.clearChoices();
}
var isDefaultValue = value === 'value'; var isDefaultValue = value === 'value';
var isDefaultLabel = label === 'label'; var isDefaultLabel = label === 'label';
choicesArrayOrFetcher.forEach(function (groupOrChoice) { choicesArrayOrFetcher.forEach(function (groupOrChoice) {
@ -3351,6 +3360,9 @@ var Choices = /** @class */ (function () {
choice = __assign(__assign({}, choice), { value: choice[value], label: choice[label] }); choice = __assign(__assign({}, choice), { value: choice[value], label: choice[label] });
} }
var choiceFull = mapInputToChoice(choice, false); var choiceFull = mapInputToChoice(choice, false);
if (!replaceItems && choiceFull.value in items) {
choiceFull.selected = true;
}
_this._addChoice(choiceFull); _this._addChoice(choiceFull);
if (choiceFull.placeholder && !_this._hasNonChoicePlaceholder) { if (choiceFull.placeholder && !_this._hasNonChoicePlaceholder) {
_this._placeholderValue = unwrapStringForEscaped(choiceFull.label); _this._placeholderValue = unwrapStringForEscaped(choiceFull.label);
@ -4718,7 +4730,7 @@ var Choices = /** @class */ (function () {
throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it")); throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it"));
} }
}; };
Choices.version = '11.0.4'; Choices.version = '11.0.5';
return Choices; return Choices;
}()); }());

View file

@ -1,4 +1,4 @@
/*! choices.js v11.0.4 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ /*! choices.js v11.0.5 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
(function (global, factory) { (function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@ -2129,13 +2129,14 @@
* }], 'value', 'label', false); * }], 'value', 'label', false);
* ``` * ```
*/ */
Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices, clearSearchFlag) { Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices, clearSearchFlag, replaceItems) {
var _this = this; var _this = this;
if (choicesArrayOrFetcher === void 0) { choicesArrayOrFetcher = []; } if (choicesArrayOrFetcher === void 0) { choicesArrayOrFetcher = []; }
if (value === void 0) { value = 'value'; } if (value === void 0) { value = 'value'; }
if (label === void 0) { label = 'label'; } if (label === void 0) { label = 'label'; }
if (replaceChoices === void 0) { replaceChoices = false; } if (replaceChoices === void 0) { replaceChoices = false; }
if (clearSearchFlag === void 0) { clearSearchFlag = true; } if (clearSearchFlag === void 0) { clearSearchFlag = true; }
if (replaceItems === void 0) { replaceItems = false; }
if (!this.initialisedOK) { if (!this.initialisedOK) {
this._warnChoicesInitFailed('setChoices'); this._warnChoicesInitFailed('setChoices');
return this; return this;
@ -2146,10 +2147,6 @@
if (typeof value !== 'string' || !value) { if (typeof value !== 'string' || !value) {
throw new TypeError("value parameter must be a name of 'value' field in passed objects"); throw new TypeError("value parameter must be a name of 'value' field in passed objects");
} }
// Clear choices if needed
if (replaceChoices) {
this.clearChoices();
}
if (typeof choicesArrayOrFetcher === 'function') { if (typeof choicesArrayOrFetcher === 'function') {
// it's a choices fetcher function // it's a choices fetcher function
var fetcher_1 = choicesArrayOrFetcher(this); var fetcher_1 = choicesArrayOrFetcher(this);
@ -2159,7 +2156,9 @@
return new Promise(function (resolve) { return requestAnimationFrame(resolve); }) return new Promise(function (resolve) { return requestAnimationFrame(resolve); })
.then(function () { return _this._handleLoadingState(true); }) .then(function () { return _this._handleLoadingState(true); })
.then(function () { return fetcher_1; }) .then(function () { return fetcher_1; })
.then(function (data) { return _this.setChoices(data, value, label, replaceChoices); }) .then(function (data) {
return _this.setChoices(data, value, label, replaceChoices, clearSearchFlag, replaceItems);
})
.catch(function (err) { .catch(function (err) {
if (!_this.config.silent) { if (!_this.config.silent) {
console.error(err); console.error(err);
@ -2183,6 +2182,16 @@
if (clearSearchFlag) { if (clearSearchFlag) {
_this._isSearching = false; _this._isSearching = false;
} }
var items = {};
if (!replaceItems) {
_this._store.items.forEach(function (item) {
items[item.value] = item;
});
}
// Clear choices if needed
if (replaceChoices) {
_this.clearChoices();
}
var isDefaultValue = value === 'value'; var isDefaultValue = value === 'value';
var isDefaultLabel = label === 'label'; var isDefaultLabel = label === 'label';
choicesArrayOrFetcher.forEach(function (groupOrChoice) { choicesArrayOrFetcher.forEach(function (groupOrChoice) {
@ -2199,6 +2208,9 @@
choice = __assign(__assign({}, choice), { value: choice[value], label: choice[label] }); choice = __assign(__assign({}, choice), { value: choice[value], label: choice[label] });
} }
var choiceFull = mapInputToChoice(choice, false); var choiceFull = mapInputToChoice(choice, false);
if (!replaceItems && choiceFull.value in items) {
choiceFull.selected = true;
}
_this._addChoice(choiceFull); _this._addChoice(choiceFull);
if (choiceFull.placeholder && !_this._hasNonChoicePlaceholder) { if (choiceFull.placeholder && !_this._hasNonChoicePlaceholder) {
_this._placeholderValue = unwrapStringForEscaped(choiceFull.label); _this._placeholderValue = unwrapStringForEscaped(choiceFull.label);
@ -3566,7 +3578,7 @@
throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it")); throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it"));
} }
}; };
Choices.version = '11.0.4'; Choices.version = '11.0.5';
return Choices; return Choices;
}()); }());

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
/*! choices.js v11.0.4 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ /*! choices.js v11.0.5 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/****************************************************************************** /******************************************************************************
Copyright (c) Microsoft Corporation. Copyright (c) Microsoft Corporation.
@ -2123,13 +2123,14 @@ var Choices = /** @class */ (function () {
* }], 'value', 'label', false); * }], 'value', 'label', false);
* ``` * ```
*/ */
Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices, clearSearchFlag) { Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices, clearSearchFlag, replaceItems) {
var _this = this; var _this = this;
if (choicesArrayOrFetcher === void 0) { choicesArrayOrFetcher = []; } if (choicesArrayOrFetcher === void 0) { choicesArrayOrFetcher = []; }
if (value === void 0) { value = 'value'; } if (value === void 0) { value = 'value'; }
if (label === void 0) { label = 'label'; } if (label === void 0) { label = 'label'; }
if (replaceChoices === void 0) { replaceChoices = false; } if (replaceChoices === void 0) { replaceChoices = false; }
if (clearSearchFlag === void 0) { clearSearchFlag = true; } if (clearSearchFlag === void 0) { clearSearchFlag = true; }
if (replaceItems === void 0) { replaceItems = false; }
if (!this.initialisedOK) { if (!this.initialisedOK) {
this._warnChoicesInitFailed('setChoices'); this._warnChoicesInitFailed('setChoices');
return this; return this;
@ -2140,10 +2141,6 @@ var Choices = /** @class */ (function () {
if (typeof value !== 'string' || !value) { if (typeof value !== 'string' || !value) {
throw new TypeError("value parameter must be a name of 'value' field in passed objects"); throw new TypeError("value parameter must be a name of 'value' field in passed objects");
} }
// Clear choices if needed
if (replaceChoices) {
this.clearChoices();
}
if (typeof choicesArrayOrFetcher === 'function') { if (typeof choicesArrayOrFetcher === 'function') {
// it's a choices fetcher function // it's a choices fetcher function
var fetcher_1 = choicesArrayOrFetcher(this); var fetcher_1 = choicesArrayOrFetcher(this);
@ -2153,7 +2150,9 @@ var Choices = /** @class */ (function () {
return new Promise(function (resolve) { return requestAnimationFrame(resolve); }) return new Promise(function (resolve) { return requestAnimationFrame(resolve); })
.then(function () { return _this._handleLoadingState(true); }) .then(function () { return _this._handleLoadingState(true); })
.then(function () { return fetcher_1; }) .then(function () { return fetcher_1; })
.then(function (data) { return _this.setChoices(data, value, label, replaceChoices); }) .then(function (data) {
return _this.setChoices(data, value, label, replaceChoices, clearSearchFlag, replaceItems);
})
.catch(function (err) { .catch(function (err) {
if (!_this.config.silent) { if (!_this.config.silent) {
console.error(err); console.error(err);
@ -2177,6 +2176,16 @@ var Choices = /** @class */ (function () {
if (clearSearchFlag) { if (clearSearchFlag) {
_this._isSearching = false; _this._isSearching = false;
} }
var items = {};
if (!replaceItems) {
_this._store.items.forEach(function (item) {
items[item.value] = item;
});
}
// Clear choices if needed
if (replaceChoices) {
_this.clearChoices();
}
var isDefaultValue = value === 'value'; var isDefaultValue = value === 'value';
var isDefaultLabel = label === 'label'; var isDefaultLabel = label === 'label';
choicesArrayOrFetcher.forEach(function (groupOrChoice) { choicesArrayOrFetcher.forEach(function (groupOrChoice) {
@ -2193,6 +2202,9 @@ var Choices = /** @class */ (function () {
choice = __assign(__assign({}, choice), { value: choice[value], label: choice[label] }); choice = __assign(__assign({}, choice), { value: choice[value], label: choice[label] });
} }
var choiceFull = mapInputToChoice(choice, false); var choiceFull = mapInputToChoice(choice, false);
if (!replaceItems && choiceFull.value in items) {
choiceFull.selected = true;
}
_this._addChoice(choiceFull); _this._addChoice(choiceFull);
if (choiceFull.placeholder && !_this._hasNonChoicePlaceholder) { if (choiceFull.placeholder && !_this._hasNonChoicePlaceholder) {
_this._placeholderValue = unwrapStringForEscaped(choiceFull.label); _this._placeholderValue = unwrapStringForEscaped(choiceFull.label);
@ -3560,7 +3572,7 @@ var Choices = /** @class */ (function () {
throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it")); throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it"));
} }
}; };
Choices.version = '11.0.4'; Choices.version = '11.0.5';
return Choices; return Choices;
}()); }());

View file

@ -142,7 +142,7 @@ declare class Choices {
* }], 'value', 'label', false); * }], 'value', 'label', false);
* ``` * ```
*/ */
setChoices(choicesArrayOrFetcher?: (InputChoice | InputGroup)[] | ((instance: Choices) => (InputChoice | InputGroup)[] | Promise<(InputChoice | InputGroup)[]>), value?: string | null, label?: string, replaceChoices?: boolean, clearSearchFlag?: boolean): this | Promise<this>; setChoices(choicesArrayOrFetcher?: (InputChoice | InputGroup)[] | ((instance: Choices) => (InputChoice | InputGroup)[] | Promise<(InputChoice | InputGroup)[]>), value?: string | null, label?: string, replaceChoices?: boolean, clearSearchFlag?: boolean, replaceItems?: boolean): this | Promise<this>;
refresh(withEvents?: boolean, selectFirstOption?: boolean, deselectAll?: boolean): this; refresh(withEvents?: boolean, selectFirstOption?: boolean, deselectAll?: boolean): this;
removeChoice(value: string): this; removeChoice(value: string): this;
clearChoices(clearOptions?: boolean): this; clearChoices(clearOptions?: boolean): this;