Search code examples
jqueryjquery-tokeninput

Token validation and pattern matching before server call


I want to check what kind of pattern the user is typing and based on that i want to make a server call. Could someone help here?

Here is what i have :

$(document).ready(function() {
    $("#search_frwId").tokenInput("http://some rest service here", {
        theme: "facebook",
        queryParam : "param"
    });
});

Solution

  • It's possible to pass a function as the first parameter of the setup (in place of a static URL.) If you can get user-input through jQuery, then you may be best to create a custom function to pattern match and generate the relevent URL string.

    i.e.

    $(document).ready(function() {
        $("#search_frwId").tokenInput(getMyRestServer, {
            theme: "facebook",
            queryParam : "param"
        });
    });
    
    function getMyRestServer(){
        var userinput = $("#search_frwId-input-facebook-theme").attr('value');
        // or if Jquery 2.x then use
        //  var userinput = $("#search_frwId-input-facebook-theme").prop('value');
        var url = "";
    
        //Do Magic Pattern Matching here
    
        return url;
    }
    

    You need to pass the function in there, not its evaluation