Reputation: 747
I have a jQuery Tokeninput which I use to select from a list of users in my system. I want to be able to limit this search to users from a specific region.
What I want to do is send the region number along with the search query. However, I can't find this functionality in the documentation. It seems to me that you can only set the query parameters when the tokeninput is created, and therefore you can't change the query afterwards, for example, when I select a new region to search from.
I know I can use the onResult function, but that's not good enough. I'm limiting the number of returned users to 15, and I want to do that AFTER filtering for region.
Upvotes: 1
Views: 1403
Reputation: 567
You can add parameters as follows
$("#my-text-input").tokenInput("domain.com?product_id=1&category_id=2");
Query string q
is automatically added and become as follows
$("#my-text-input").tokenInput("domain.com?product_id=1&category_id=2&q=searched string");
Upvotes: 0
Reputation: 9267
this can be done by onSend
callback of the plugin
onSend: function(request_params) {
console.log(request_params);
// manipulate request_params object
}
my answer on similar question jquery tokeninput filter query send extra parameters
Upvotes: 0
Reputation: 6042
You can pass a function to the constructor, rather than a specific URL. In this function, you can then return a string, with the 'region' you require as a GET
parameter.
Say you were currently doing something like this...
$("#search_frwId").tokenInput("www.example.com?region=UK");
You could instead do....
$("#search_frwId").tokenInput(getRegionURL);
function getRegionURL(){
if (uk_region_selected) return "www.example.com?region=UK";
else return "www.example.com?region=US";
}
Upvotes: 1