Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed the issue described in #50 and #53: When a list has been pre-po…

…pulated with one value and the limit on tokens is 1, then I am still allowed to add 2 tokens.
  • Loading branch information...
commit 86ae6e3b54315a4cca96b5c84bf3361355776e5b 1 parent 92bf8d8
@otaviomedeiros otaviomedeiros authored
Showing with 12 additions and 8 deletions.
  1. +12 −8 src/jquery.tokeninput.js
View
20 src/jquery.tokeninput.js
@@ -317,6 +317,7 @@ $.TokenList = function (input, url_or_data, settings) {
if(li_data && li_data.length) {
$.each(li_data, function (index, value) {
insert_token(value.id, value.name);
+ checkTokenLimit();
});
}
@@ -326,6 +327,16 @@ $.TokenList = function (input, url_or_data, settings) {
// Private functions
//
+ function checkTokenLimit(){
+ if(settings.tokenLimit !== null && token_count >= settings.tokenLimit) {
+ input_box.hide();
+ hide_dropdown();
+ return;
+ } else {
+ input_box.focus();
+ }
+ }
+
function resize_input() {
if(input_val === (input_val = input_box.val())) {return;}
@@ -404,14 +415,7 @@ $.TokenList = function (input, url_or_data, settings) {
// Insert the new tokens
insert_token(li_data.id, li_data.name);
- // Check the token limit
- if(settings.tokenLimit !== null && token_count >= settings.tokenLimit) {
- input_box.hide();
- hide_dropdown();
- return;
- } else {
- input_box.focus();
- }
+ checkTokenLimit();
// Clear input box
input_box.val("");
Please sign in to comment.
Something went wrong with that request. Please try again.