Programmably insert a list of selections

Mountain's Avatar


16 Jun, 2010 05:07 PM

Is it possible to programmably insert a list of selections (data) to the text field? The data inserted should be working exactly the same as the manually selected one, e.g. it can be closed/removed, and can be submitted via the form etc.

Basically I have another field that queries a set of data based on a keyword, and I want to add these data to the autoSuggest text field in one go so that the user does not need to enter the data one by one.

Many thanks for your help.

  1. 1 Posted by Neiloy on 16 Jun, 2010 10:09 PM

    Neiloy's Avatar

    I also need to do something quite like this (moving data into the type-ahead box after it's already been instantiated) - some sort of interface for doing so would be very useful.

  2. 2 Posted by Nick on 25 Aug, 2010 11:31 AM

    Nick's Avatar

    That would be great!!!! I am also interested in this feature

  3. 3 Posted by Gaurav on 29 Aug, 2010 06:44 AM

    Gaurav's Avatar

    I would also like to be able to programmatically insert a selection (i.e. preload a recipient of a message) as well as clear all selections (i.e. reset a form). Right now there are workarounds for this (everything has an id and class), but it would be great to see it as part of the AutoSuggest API.


  4. 4 Posted by alex on 13 Sep, 2010 03:20 PM

    alex's Avatar

    You can add selected item like this:

    var data = new Object(); = "Google";
    data.value = "";
    $.autoSuggest.add_selected_item(data, Math.floor(Math.random() * 11));

  5. 5 Posted by alex on 13 Sep, 2010 03:21 PM

    alex 's Avatar

    file attached!

  6. 6 Posted by Dan Imbrogno on 20 Sep, 2010 09:35 PM

    Dan Imbrogno's Avatar

    How would you go about completely replacing the existing data set with a new one? I have a french and english data set that I want to switch when the user changes the active language, but I can't figure out a way to re-initialize the auto-suggest box, or remove the data set and attach a new one.

    Any help would be greatly appreciated.

  7. 7 Posted by Dan Imbrogno on 20 Sep, 2010 10:34 PM

    Dan Imbrogno's Avatar

    Okay, this is kind of a hacky way of doing this but it may help someone. What I've done to reset the form is essentially to add the search input box programmatically, and then when I want to re-initalize the data set, I simply remove the input box, and then re-add it, and then re-attach the autoSuggest behaviour.

    $('#search_holder').html(''); $('#search_holder').html('');


  8. 8 Posted by Dan Imbrogno on 21 Sep, 2010 06:25 PM

    Dan Imbrogno's Avatar

    Sorry, the filters on comments made what I wrote above nonsensical. Here's a link to an example:

  9. 9 Posted by Amit on 24 Dec, 2010 05:55 AM

    Amit's Avatar

    Thanks Dan, for saving me a weekend!!

  10. 10 Posted by Jim on 05 Jun, 2012 06:15 PM

    Jim's Avatar

    @alex, thank you for the code, it worked great for me

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac