- Add support of custom labels for i18n purpose

This commit is contained in:
fabien.leconte 2016-11-07 11:27:04 +01:00
parent 07915df37a
commit 8be12c20cd
5 changed files with 76 additions and 69 deletions

View file

@ -1,4 +1,4 @@
/*! choices.js v2.4.0 | (c) 2016 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/*! choices.js v2.4.1 | (c) 2016 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
@ -74,11 +74,11 @@ return /******/ (function(modules) { // webpackBootstrap
var _index2 = _interopRequireDefault(_index);
var _index3 = __webpack_require__(23);
var _index3 = __webpack_require__(22);
var _utils = __webpack_require__(24);
var _utils = __webpack_require__(23);
__webpack_require__(25);
__webpack_require__(24);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@ -138,6 +138,13 @@ return /******/ (function(modules) { // webpackBootstrap
noResultsText: 'No results found',
noChoicesText: 'No choices to choose from',
itemSelectText: 'Press to select',
addItemText: function addItemText(value) {
return 'Press Enter to add <b>"' + value + '"</b>';
},
maxItemText: function maxItemText(maxItemCount) {
return 'Only ' + maxItemCount + ' values can be added.';
},
uniqueItemText: 'Only unique values can be added.',
classNames: {
containerOuter: 'choices',
containerInner: 'choices__inner',
@ -1243,14 +1250,14 @@ return /******/ (function(modules) { // webpackBootstrap
key: '_canAddItem',
value: function _canAddItem(activeItems, value) {
var canAddItem = true;
var notice = 'Press Enter to add <b>"' + value + '"</b>';
var notice = (0, _utils.isType)('Function', this.config.addItemText) ? this.config.addItemText(value) : this.config.addItemText;
if (this.passedElement.type === 'select-multiple' || this.passedElement.type === 'text') {
if (this.config.maxItemCount > 0 && this.config.maxItemCount <= this.itemList.children.length) {
// If there is a max entry limit and we have reached that limit
// don't update
canAddItem = false;
notice = 'Only ' + this.config.maxItemCount + ' values can be added.';
notice = (0, _utils.isType)('Function', this.config.maxItemText) ? this.config.maxItemText(this.config.maxItemCount) : this.config.maxItemText;
}
}
@ -1270,7 +1277,7 @@ return /******/ (function(modules) { // webpackBootstrap
// in the array
if (this.config.duplicateItems === false && !isUnique) {
canAddItem = false;
notice = 'Only unique values can be added.';
notice = (0, _utils.isType)('Function', this.config.uniqueItemText) ? this.config.uniqueItemText(value) : this.config.uniqueItemText;
}
}
@ -3352,7 +3359,7 @@ return /******/ (function(modules) { // webpackBootstrap
var _redux = __webpack_require__(4);
var _index = __webpack_require__(19);
var _index = __webpack_require__(18);
var _index2 = _interopRequireDefault(_index);
@ -3584,23 +3591,23 @@ return /******/ (function(modules) { // webpackBootstrap
var _createStore2 = _interopRequireDefault(_createStore);
var _combineReducers = __webpack_require__(14);
var _combineReducers = __webpack_require__(13);
var _combineReducers2 = _interopRequireDefault(_combineReducers);
var _bindActionCreators = __webpack_require__(16);
var _bindActionCreators = __webpack_require__(15);
var _bindActionCreators2 = _interopRequireDefault(_bindActionCreators);
var _applyMiddleware = __webpack_require__(17);
var _applyMiddleware = __webpack_require__(16);
var _applyMiddleware2 = _interopRequireDefault(_applyMiddleware);
var _compose = __webpack_require__(18);
var _compose = __webpack_require__(17);
var _compose2 = _interopRequireDefault(_compose);
var _warning = __webpack_require__(15);
var _warning = __webpack_require__(14);
var _warning2 = _interopRequireDefault(_warning);
@ -4041,55 +4048,32 @@ return /******/ (function(modules) { // webpackBootstrap
/* 11 */
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global, module) {'use strict';
/* WEBPACK VAR INJECTION */(function(global) {'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
var _ponyfill = __webpack_require__(13);
var _ponyfill = __webpack_require__(12);
var _ponyfill2 = _interopRequireDefault(_ponyfill);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var root; /* global window */
var root = undefined; /* global window */
if (typeof self !== 'undefined') {
root = self;
if (typeof global !== 'undefined') {
root = global;
} else if (typeof window !== 'undefined') {
root = window;
} else if (typeof global !== 'undefined') {
root = global;
} else if (true) {
root = module;
} else {
root = Function('return this')();
root = window;
}
var result = (0, _ponyfill2['default'])(root);
exports['default'] = result;
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()), __webpack_require__(12)(module)))
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
/***/ },
/* 12 */
/***/ function(module, exports) {
module.exports = function(module) {
if(!module.webpackPolyfill) {
module.deprecate = function() {};
module.paths = [];
// module.parent = undefined by default
module.children = [];
module.webpackPolyfill = 1;
}
return module;
}
/***/ },
/* 13 */
/***/ function(module, exports) {
'use strict';
@ -4117,7 +4101,7 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/* 14 */
/* 13 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@ -4131,7 +4115,7 @@ return /******/ (function(modules) { // webpackBootstrap
var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
var _warning = __webpack_require__(15);
var _warning = __webpack_require__(14);
var _warning2 = _interopRequireDefault(_warning);
@ -4264,7 +4248,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
/***/ },
/* 15 */
/* 14 */
/***/ function(module, exports) {
'use strict';
@ -4294,7 +4278,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
/***/ },
/* 16 */
/* 15 */
/***/ function(module, exports) {
'use strict';
@ -4350,7 +4334,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
/***/ },
/* 17 */
/* 16 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@ -4361,7 +4345,7 @@ return /******/ (function(modules) { // webpackBootstrap
exports['default'] = applyMiddleware;
var _compose = __webpack_require__(18);
var _compose = __webpack_require__(17);
var _compose2 = _interopRequireDefault(_compose);
@ -4413,7 +4397,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
/***/ },
/* 18 */
/* 17 */
/***/ function(module, exports) {
"use strict";
@ -4456,7 +4440,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
/***/ },
/* 19 */
/* 18 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@ -4467,15 +4451,15 @@ return /******/ (function(modules) { // webpackBootstrap
var _redux = __webpack_require__(4);
var _items = __webpack_require__(20);
var _items = __webpack_require__(19);
var _items2 = _interopRequireDefault(_items);
var _groups = __webpack_require__(21);
var _groups = __webpack_require__(20);
var _groups2 = _interopRequireDefault(_groups);
var _choices = __webpack_require__(22);
var _choices = __webpack_require__(21);
var _choices2 = _interopRequireDefault(_choices);
@ -4503,7 +4487,7 @@ return /******/ (function(modules) { // webpackBootstrap
exports.default = rootReducer;
/***/ },
/* 20 */
/* 19 */
/***/ function(module, exports) {
'use strict';
@ -4571,7 +4555,7 @@ return /******/ (function(modules) { // webpackBootstrap
exports.default = items;
/***/ },
/* 21 */
/* 20 */
/***/ function(module, exports) {
'use strict';
@ -4612,7 +4596,7 @@ return /******/ (function(modules) { // webpackBootstrap
exports.default = groups;
/***/ },
/* 22 */
/* 21 */
/***/ function(module, exports) {
'use strict';
@ -4740,7 +4724,7 @@ return /******/ (function(modules) { // webpackBootstrap
exports.default = choices;
/***/ },
/* 23 */
/* 22 */
/***/ function(module, exports) {
'use strict';
@ -4825,7 +4809,7 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/* 24 */
/* 23 */
/***/ function(module, exports) {
"use strict";
@ -5307,7 +5291,7 @@ return /******/ (function(modules) { // webpackBootstrap
};
/***/ },
/* 25 */
/* 24 */
/***/ function(module, exports) {
'use strict';

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -71,6 +71,13 @@ class Choices {
noResultsText: 'No results found',
noChoicesText: 'No choices to choose from',
itemSelectText: 'Press to select',
addItemText: (value) => {
return `Press Enter to add <b>"${value}"</b>`;
},
maxItemText: (maxItemCount) => {
return `Only ${maxItemCount} values can be added.`;
},
uniqueItemText: 'Only unique values can be added.',
classNames: {
containerOuter: 'choices',
containerInner: 'choices__inner',
@ -1032,14 +1039,14 @@ class Choices {
*/
_canAddItem(activeItems, value) {
let canAddItem = true;
let notice = `Press Enter to add <b>"${value}"</b>`;
let notice = isType('Function', this.config.addItemText) ? this.config.addItemText(value) : this.config.addItemText;
if (this.passedElement.type === 'select-multiple' || this.passedElement.type === 'text') {
if (this.config.maxItemCount > 0 && this.config.maxItemCount <= this.itemList.children.length) {
// If there is a max entry limit and we have reached that limit
// don't update
canAddItem = false;
notice = `Only ${this.config.maxItemCount} values can be added.`;
notice = isType('Function', this.config.maxItemText) ? this.config.maxItemText(this.config.maxItemCount) : this.config.maxItemText;
}
}
@ -1057,7 +1064,7 @@ class Choices {
// in the array
if (this.config.duplicateItems === false && !isUnique) {
canAddItem = false;
notice = 'Only unique values can be added.';
notice = isType('Function', this.config.uniqueItemText) ? this.config.uniqueItemText(value) : this.config.uniqueItemText;
}
}

View file

@ -65,7 +65,10 @@
<label for="choices-text-preset-values">Preset values passed through options</label>
<input class="form-control" id="choices-text-preset-values" type="text" value="olivia@benson.com" placeholder="This is a placeholder">
<label for="choices-text-preset-values">Right-to-left</label>
<label for="choices-text-i18n">I18N labels</label>
<input class="form-control" data-trigger id="choices-text-i18n" type="text">
<label for="choices-text-rtl">Right-to-left</label>
<input class="form-control" data-trigger id="choices-text-rtl" type="text" value="Value 1, Value 2" dir="rtl">
<hr>
@ -276,6 +279,19 @@
editItems: true,
});
var texti18n = new Choices('#choices-text-i18n', {
paste: false,
duplicateItems: false,
editItems: true,
addItemText: (value) => {
return `Appuyez sur Entrée pour ajouter <b>"${value}"</b>`;
},
maxItemText: (maxItemCount) => {
return `${maxItemCount} valeurs peuvent être ajoutées`;
},
uniqueItemText: 'Cette valeur est déjà présente',
});
var textEmailFilter = new Choices('#choices-text-email-filter', {
editItems: true,
regexFilter: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,