Rename duplicateItems to duplicateItemsAllowed for clarity

This commit is contained in:
Josh Johnson 2018-05-29 09:30:05 +01:00
parent f286dbc653
commit 8a21c12482
9 changed files with 66 additions and 62 deletions

View file

@ -69,7 +69,7 @@ Or include Choices directly:
removeItems: true, removeItems: true,
removeItemButton: false, removeItemButton: false,
editItems: false, editItems: false,
duplicateItems: true, duplicateItemsAllowed: true,
delimiter: ',', delimiter: ',',
paste: true, paste: true,
searchEnabled: true, searchEnabled: true,
@ -256,12 +256,12 @@ Pass an array of objects:
**Usage:** Whether a user can edit items. An item's value can be edited by pressing the backspace. **Usage:** Whether a user can edit items. An item's value can be edited by pressing the backspace.
### duplicateItems ### duplicateItemsAllowed
**Type:** `Boolean` **Default:** `true` **Type:** `Boolean` **Default:** `true`
**Input types affected:** `text`, `select-multiple` **Input types affected:** `text`, `select-multiple`
**Usage:** Whether each inputted/chosen item should be unique. **Usage:** Whether duplicate inputted/chosen items are allowed
### delimiter ### delimiter
**Type:** `String` **Default:** `,` **Type:** `String` **Default:** `,`

View file

@ -1,4 +1,4 @@
/*! choices.js v4.0.0 | (c) 2018 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ /*! choices.js v4.0.0 | (c) 2018 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
(function webpackUniversalModuleDefinition(root, factory) { (function webpackUniversalModuleDefinition(root, factory) {
//CommonJS2 //CommonJS2
if(typeof exports === 'object' && typeof module === 'object') if(typeof exports === 'object' && typeof module === 'object')
@ -577,7 +577,7 @@ var DEFAULT_CONFIG = exports.DEFAULT_CONFIG = {
removeItems: true, removeItems: true,
removeItemButton: false, removeItemButton: false,
editItems: false, editItems: false,
duplicateItems: true, duplicateItemsAllowed: true,
delimiter: ',', delimiter: ',',
paste: true, paste: true,
searchEnabled: true, searchEnabled: true,
@ -1843,27 +1843,27 @@ if (false) {
/* 31 */ /* 31 */
/***/ (function(module, exports) { /***/ (function(module, exports) {
var g; var g;
// This works in non-strict mode // This works in non-strict mode
g = (function() { g = (function() {
return this; return this;
})(); })();
try { try {
// This works if eval is allowed (see CSP) // This works if eval is allowed (see CSP)
g = g || Function("return this")() || (1,eval)("this"); g = g || Function("return this")() || (1,eval)("this");
} catch(e) { } catch(e) {
// This works if the window reference is available // This works if the window reference is available
if(typeof window === "object") if(typeof window === "object")
g = window; g = window;
} }
// g can still be undefined, but nothing to do about it... // g can still be undefined, but nothing to do about it...
// We return undefined, instead of nothing here, so it's // We return undefined, instead of nothing here, so it's
// easier to handle this case. if(!global) { ...} // easier to handle this case. if(!global) { ...}
module.exports = g; module.exports = g;
/***/ }), /***/ }),
@ -2975,7 +2975,7 @@ var Choices = function () {
canAddItem = (0, _utils.regexFilter)(value, this.config.regexFilter); canAddItem = (0, _utils.regexFilter)(value, this.config.regexFilter);
} }
if (!this.config.duplicateItems && !valueAlreadyExists && canAddItem) { if (!this.config.duplicateItemsAllowed && !valueAlreadyExists && canAddItem) {
canAddItem = false; canAddItem = false;
notice = (0, _utils.isType)('Function', this.config.uniqueItemText) ? this.config.uniqueItemText(value) : this.config.uniqueItemText; notice = (0, _utils.isType)('Function', this.config.uniqueItemText) ? this.config.uniqueItemText(value) : this.config.uniqueItemText;
} }
@ -4113,10 +4113,10 @@ module.exports = Choices;
/*! /*!
* Fuse.js v3.2.0 - Lightweight fuzzy-search (http://fusejs.io) * Fuse.js v3.2.0 - Lightweight fuzzy-search (http://fusejs.io)
* *
* Copyright (c) 2012-2017 Kirollos Risk (http://kiro.me) * Copyright (c) 2012-2017 Kirollos Risk (http://kiro.me)
* All Rights Reserved. Apache Software License 2.0 * All Rights Reserved. Apache Software License 2.0
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
*/ */
(function webpackUniversalModuleDefinition(root, factory) { (function webpackUniversalModuleDefinition(root, factory) {
@ -5987,30 +5987,30 @@ var result = Object(__WEBPACK_IMPORTED_MODULE_0__ponyfill_js__["a" /* default */
/* 66 */ /* 66 */
/***/ (function(module, exports) { /***/ (function(module, exports) {
module.exports = function(originalModule) { module.exports = function(originalModule) {
if(!originalModule.webpackPolyfill) { if(!originalModule.webpackPolyfill) {
var module = Object.create(originalModule); var module = Object.create(originalModule);
// module.parent = undefined by default // module.parent = undefined by default
if(!module.children) module.children = []; if(!module.children) module.children = [];
Object.defineProperty(module, "loaded", { Object.defineProperty(module, "loaded", {
enumerable: true, enumerable: true,
get: function() { get: function() {
return module.l; return module.l;
} }
}); });
Object.defineProperty(module, "id", { Object.defineProperty(module, "id", {
enumerable: true, enumerable: true,
get: function() { get: function() {
return module.i; return module.i;
} }
}); });
Object.defineProperty(module, "exports", { Object.defineProperty(module, "exports", {
enumerable: true, enumerable: true,
}); });
module.webpackPolyfill = 1; module.webpackPolyfill = 1;
} }
return module; return module;
}; };
/***/ }), /***/ }),

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -316,13 +316,13 @@
var textUniqueVals = new Choices('#choices-text-unique-values', { var textUniqueVals = new Choices('#choices-text-unique-values', {
paste: false, paste: false,
duplicateItems: false, duplicateItemsAllowed: false,
editItems: true, editItems: true,
}); });
var texti18n = new Choices('#choices-text-i18n', { var texti18n = new Choices('#choices-text-i18n', {
paste: false, paste: false,
duplicateItems: false, duplicateItemsAllowed: false,
editItems: true, editItems: true,
maxItemCount: 5, maxItemCount: 5,
addItemText: function(value) { addItemText: function(value) {

View file

@ -802,7 +802,7 @@ class Choices {
: this.config.addItemText; : this.config.addItemText;
if (!this._isSelectOneElement) { if (!this._isSelectOneElement) {
const valueAlreadyExists = !existsInArray(activeItems, value); const isDuplicateValue = existsInArray(activeItems, value);
if ( if (
this.config.maxItemCount > 0 && this.config.maxItemCount > 0 &&
@ -828,7 +828,11 @@ class Choices {
canAddItem = regexFilter(value, this.config.regexFilter); canAddItem = regexFilter(value, this.config.regexFilter);
} }
if (!this.config.duplicateItems && !valueAlreadyExists && canAddItem) { if (
!this.config.duplicateItemsAllowed &&
isDuplicateValue &&
canAddItem
) {
canAddItem = false; canAddItem = false;
notice = isType('Function', this.config.uniqueItemText) notice = isType('Function', this.config.uniqueItemText)
? this.config.uniqueItemText(value) ? this.config.uniqueItemText(value)

View file

@ -39,7 +39,7 @@ export const DEFAULT_CONFIG = {
removeItems: true, removeItems: true,
removeItemButton: false, removeItemButton: false,
editItems: false, editItems: false,
duplicateItems: true, duplicateItemsAllowed: true,
delimiter: ',', delimiter: ',',
paste: true, paste: true,
searchEnabled: true, searchEnabled: true,

View file

@ -59,7 +59,7 @@ describe('constants', () => {
expect(DEFAULT_CONFIG.removeItems).to.be.a('boolean'); expect(DEFAULT_CONFIG.removeItems).to.be.a('boolean');
expect(DEFAULT_CONFIG.removeItemButton).to.be.a('boolean'); expect(DEFAULT_CONFIG.removeItemButton).to.be.a('boolean');
expect(DEFAULT_CONFIG.editItems).to.be.a('boolean'); expect(DEFAULT_CONFIG.editItems).to.be.a('boolean');
expect(DEFAULT_CONFIG.duplicateItems).to.be.a('boolean'); expect(DEFAULT_CONFIG.duplicateItemsAllowed).to.be.a('boolean');
expect(DEFAULT_CONFIG.delimiter).to.be.a('string'); expect(DEFAULT_CONFIG.delimiter).to.be.a('string');
expect(DEFAULT_CONFIG.paste).to.be.a('boolean'); expect(DEFAULT_CONFIG.paste).to.be.a('boolean');
expect(DEFAULT_CONFIG.searchEnabled).to.be.a('boolean'); expect(DEFAULT_CONFIG.searchEnabled).to.be.a('boolean');

2
types/index.d.ts vendored
View file

@ -320,7 +320,7 @@ declare namespace Choices {
* *
* @default true * @default true
*/ */
duplicateItems?: boolean; duplicateItemsAllowed?: boolean;
/** /**
* What divides each value. The default delimiter seperates each value with a comma: `"Value 1, Value 2, Value 3"`. * What divides each value. The default delimiter seperates each value with a comma: `"Value 1, Value 2, Value 3"`.