diff --git a/src/jquery.tokeninput.js b/src/jquery.tokeninput.js index ef5141be..a2818cc8 100644 --- a/src/jquery.tokeninput.js +++ b/src/jquery.tokeninput.js @@ -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(); + } }