save pending tags when clicking OK on tagPrompt

pull/1/head
ansuz 7 years ago
parent 39d8e2dd81
commit 3c2d6af4f0

@ -1,4 +1,4 @@
define([ /efine([
'jquery', 'jquery',
'/customize/messages.js', '/customize/messages.js',
'/common/common-util.js', '/common/common-util.js',
@ -130,10 +130,19 @@ define([
element: target || h('input'), element: target || h('input'),
}; };
var $t = t.tokenfield = $(t.element).tokenfield(); var $t = t.tokenfield = $(t.element).tokenfield();
t.getTokens = function () {
return $t.tokenfield('getTokens').map(function (token) { t.getTokens = function (ignorePending) {
var tokens = $t.tokenfield('getTokens').map(function (token) {
return token.value.toLowerCase(); return token.value.toLowerCase();
}); });
if (ignorePending) { return tokens; }
var $pendingEl = $($t.parent().find('.token-input')[0]);
var val = ($pendingEl.val() || "").trim();
if (val && tokens.indexOf(val) === -1) {
return tokens.concat(val);
}
return tokens;
}; };
var $root = $t.parent(); var $root = $t.parent();
@ -145,7 +154,7 @@ define([
$t.on('tokenfield:createtoken', function (ev) { $t.on('tokenfield:createtoken', function (ev) {
var val; var val;
ev.attrs.value = ev.attrs.value.toLowerCase(); ev.attrs.value = ev.attrs.value.toLowerCase();
if (t.getTokens().some(function (t) { if (t.getTokens(true).some(function (t) {
if (t === ev.attrs.value) { return ((val = t)); } if (t === ev.attrs.value) { return ((val = t)); }
})) { })) {
ev.preventDefault(); ev.preventDefault();

Loading…
Cancel
Save