How to change Token Limit Dynamically in onadd function of jquery token input?

1.2k views Asked by At

Same problem as Changing Token Limit Dynamically on add function of jquery token input

I need to change the token limit of a token input textbox dynamically based on its add and on delete functions. In my case when the user selects an item called "text" from the list, the token limit should change to 1 otherwise null.

  $("[id$=searchbox]").tokenInput(itemsArray, 
  {
         onAdd: function(item) 
         {     
              //What to write here to set token limit 
         }
  });
1

There are 1 answers

2
Sergiu Paraschiv On

If you read the sources you find out that the tokenLimit setting is always read from $(input).data("settings").tokenLimit.

This means you can also set it from outside at any time.

$("[id$=searchbox]").tokenInput(itemsArray, {
     onAdd: function(item) {
         if(!$("[id$=searchbox]").data("settings")) {
             $("[id$=searchbox]").data("settings", {});
         }
         $("[id$=searchbox]").data("settings").tokenLimit = 10;
     }
});

Now add your custom logic.