Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
make tokenLimit and prePopulate work together
Browse files Browse the repository at this point in the history
  • Loading branch information
vdepizzol committed May 20, 2011
1 parent 3d355b3 commit ab52568
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/jquery.tokeninput.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,24 @@ $.TokenList = function (input, url_or_data, settings) {

// Pre-populate list if items exist
hidden_input.val("");

var li_data = settings.prePopulate || hidden_input.data("pre");
if(settings.processPrePopulate && $.isFunction(settings.onResult)) {
li_data = settings.onResult.call(hidden_input, li_data);
}
}
if(li_data && li_data.length) {
$.each(li_data, function (index, value) {
insert_token(value);
if(settings.tokenLimit == null || settings.tokenLimit >= (index+1)) {
insert_token(value);
} else {
return false;
}
});

if(li_data.length >= settings.tokenLimit && settings.tokenLimit != null) {
input_box.hide();
hide_dropdown();
}
}


Expand Down

0 comments on commit ab52568

Please sign in to comment.