1

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.

3 Answers 3

1

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";
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the suggestion @Chris. However, I have to be able to change the region after I've instantiated the tokenInput, that's what I mean by dynamically. Luckily, I may have found a solution. When the region is changed, I store the values selected so far in the tokenInput, remove the tokenInput from the textarea and instantiate it again using the prePopulate setting, passing in the values I stored.
I'll confirm that this works once I've done some further testing.
@Asgeir - Sorry, I've explained poorly. If you instantiate with a function, then the function is called on each search, rather than a specific string url used. I don't know how you're 'changing the region' in your interface, but say they were radio buttons, you could test if each was selected in your getRegionURL() function, which would be called on each search.
0

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

Comments

0

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");

Comments

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.