0

I want to know how to stop inputting same pattern value in TokenInput using Jquery ?

For Example : If i have something like "GM-123" and i dont want to have "GM-345" in the input field then what should i do ?

Anyone , please help.

af_khan
  • 1,030
  • 4
  • 25
  • 49

1 Answers1

0

I would make use of the onAdd callback, which is called when a token is added, and then remove the token if it shouldn't be allowed. Use something like this in your set up:

$(document).ready(function() {
    $("#search_frwId").tokenInput(getMyRestServer, {
        theme: "facebook",
        queryParam: "param",
        onAdd: function(hidden_input,item){
             var newInput = item.name;

             //Pattern Matching Magic Here

             if(shouldNotBeAdded) $("#search_frwId").tokenInput("remove", item);
        }
    });
});

(This is untested code, I think passing the item back into remove like that will work, but am not 100% sure!)

Chris
  • 5,882
  • 2
  • 32
  • 57
  • 1
    Hi , I got busy with some priority work on the backlog and dint get time to check this. I will update this question once i succeed. Thanks – af_khan Mar 13 '14 at 09:22