Enable tags in pads

This commit is contained in:
yflory
2017-09-19 15:30:08 +02:00
parent 6683434c62
commit 8a09e39f46
12 changed files with 93 additions and 23 deletions

View File

@@ -131,13 +131,14 @@ define([
var $t = t.tokenfield = $(t.element).tokenfield();
t.getTokens = function () {
return $t.tokenfield('getTokens').map(function (token) {
return token.value;
return token.value.toLowerCase();
});
};
t.preventDuplicates = function (cb) {
$t.on('tokenfield:createtoken', function (ev) {
var val;
ev.attrs.value = ev.attrs.value.toLowerCase();
if (t.getTokens().some(function (t) {
if (t === ev.attrs.value) { return ((val = t)); }
})) {
@@ -152,8 +153,8 @@ define([
$t.tokenfield('setTokens',
tokens.map(function (token) {
return {
value: token,
label: token,
value: token.toLowerCase(),
label: token.toLowerCase(),
};
}));
};
@@ -171,13 +172,13 @@ define([
var input = dialog.textInput();
var tagger = dialog.frame([
dialog.message('make some tags'), // TODO translate
dialog.message(Messages.tags_add),
input,
dialog.nav(),
]);
var field = UI.tokenField(input).preventDuplicates(function (val) {
UI.warn('Duplicate tag: ' + val); // TODO translate
UI.warn(Messages._getKey('tags_duplicate', [val]));
});
var close = Util.once(function () {