Skip to content
This repository has been archived by the owner on May 9, 2018. It is now read-only.

Commit

Permalink
Fixing bug where tags added via autocomplete did not respect "maxTags…
Browse files Browse the repository at this point in the history
…" option
  • Loading branch information
Matthew Hailwood committed Jul 19, 2012
1 parent 6ca832c commit 645558d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
15 changes: 11 additions & 4 deletions js/tagit-themeroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
tagsChanged:function (tagValue, action, element) {
;
},
maxTags: undefined,
//should 'paste' event trigger 'blur', thus potentially adding a new tag
// (true for backwards compatibility)
blurOnPaste:true
Expand Down Expand Up @@ -115,10 +116,16 @@
this.options.select = function (event, ui) {
self.input.data('autoCompleteTag', true);
clearTimeout(self.timer);
if (ui.item.label === undefined)
self._addTag(ui.item.value);
else
self._addTag(ui.item.label, ui.item.value);
if (self.options.maxTags !== undefined && self.tagsArray.length == self.options.maxTags) {
self.input.val("");
}
else {
if (ui.item.label === undefined)
self._addTag(ui.item.value);
else
self._addTag(ui.item.label, ui.item.value);
}

return false;
}

Expand Down
11 changes: 9 additions & 2 deletions js/tagit.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
tagsChanged:function (tagValue, action, element) {
;
},
maxTags:undefined,
//should 'paste' event trigger 'blur', thus potentially adding a new tag
// (true for backwards compatibility)
blurOnPaste:true
Expand Down Expand Up @@ -114,14 +115,20 @@
this.options.source = this.options.tagSource;
this.options.select = function (event, ui) {
self.input.data('autoCompleteTag', true);
clearTimeout(self.timer);
clearTimeout(self.timer);
if (self.options.maxTags !== undefined && self.tagsArray.length == self.options.maxTags) {
self.input.val("");
}
else {
if (ui.item.label === undefined)
self._addTag(ui.item.value);
else
self._addTag(ui.item.label, ui.item.value);
return false;
}

return false;
},

this.options.focus = function (event, ui) {
if (ui.item.label !== undefined && /^key/.test(event.originalEvent.originalEvent.type)) {
self.input.val(ui.item.label);
Expand Down

0 comments on commit 645558d

Please sign in to comment.