5

How can I set extra parameters to the query like

q=myseed&filter=1,2,34

better will be with a attached event like

onFocus:function(){
  //retrieve extra params
}

Here is a link to the plugin - http://loopj.com/jquery-tokeninput/

2
  • 1
    The author of the plugin simply did not provide this functionality... Commented Aug 14, 2012 at 11:10
  • @Lix, now it is possible, pls see my answer stackoverflow.com/a/31720287/932473 Commented Jul 30, 2015 at 9:42

5 Answers 5

3

Here is how you could do it, in the example below I am passing two extra param to the tokenInput url.

this.$("#abcTextbox").tokenInput("url?someParam1=cricket&someParam2=yasser", {
    queryParam: "q"
});

Source

Sign up to request clarification or add additional context in comments.

Comments

2

another way to do it, you can use initial url to achieve this.

something like :

$("#selector").tokenInput("PATH_TO_SCRIPT&filter=1,2,3", {
  queryParam: "q"
});

this will be processed as expected

2 Comments

This will not work. It will be sent as PATH_TO_SCRIPT&filter=1,2,3?q=term to the server
This actually work, but you have to do not declare the query param at all, and instead of "&" use "?": ''' $("#selector").tokenInput("PATH_TO_SCRIPT?filter=1,2,3",{you settings}); '''
2

I know that question is quite old but i had the same problem and found an answer.

Looking at the source, the url parameter can be a function that is evaled before sending the ajax query. So you can do :

this.$("#abcTextbox").tokenInput(function(){
    return "/path/to/script.php?filter="+$("#myFieldId").val()
}, {
    queryParam: "q"
 ...
});

2 Comments

The url is cached however. Only works the first time.
@darethas Just verified that in version 1.6.0 the url function result is not cached. It's executed once in initialization and then twice for each search, once to compute the cache key and a second time for the ajax url.
2

This is possible by the plugin's native functionality(at least with the current version), it is just not written in the documentation: there is onSend callback in the code. Here is simple example

$(".my-input").tokenInput('autocomplete.php', {
    hintText: false,
    onSend: function(param1) {
        // console.log($(this));
        // console.log(param1);
        param1.data.my_key = 'my_value';
    }
});

Comments

1

Besides going into the actual plugin code and adding this feature the only other way I can see doing this is by changing the queryParam to something like -

filter=1,2,34&q

That way your filter is simply appended to the actual query parameter. It'd have to be hard coded and you will probably have to reinitialize the plugin every time you want to alter this additional filter.

Example -

$("#selector").tokenInput("PATH_TO_SCRIPT", {
  queryParam: "filter=1,2,34&q"
});

4 Comments

Thanks for the reply.[. It'd have to be hard coded and you will probably have to reinitialize the plugin every time you want to alter this additional filter.] thats the problem :(
Well like I said in my first comment, this simply is not a feature that is provided, so you'll have to hack it..
setting a cookie value might help... you can set the filter there and read it server side.... or a session variable via AJAX is also an option...
this does not work, since the result will hold url non encoded caracters and you will endup with this: path_to_script?filter%3D1,2,3%26q=

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.