Bug removing elements

Vadim Geshel's Avatar

Vadim Geshel

31 Mar, 2010 12:46 AM

I think you have a bug with removing (either by mouseclick or by backspace) the first element from the box. This:


Doesn't match the first element because it doesn't have a leading comma.

A patch is attached.

Thanks for a great plugin!

  1. Support Staff 1 Posted by Drew Wilson on 17 May, 2010 07:37 PM

    Drew Wilson's Avatar

    i cannont replicate this bug.. can you describe your situation?

  2. 2 Posted by Cisco Chung on 06 Jun, 2010 12:44 PM

    Cisco Chung's Avatar


    I am also having this problem, however, this code is a little strange - can you please attach the complete file?? does anyone have an updated bug free version??

  3. 3 Posted by Mike Murray on 08 Jun, 2010 06:27 PM

    Mike Murray's Avatar

    I'm getting a similar problem when I add an item, then remove it. It removes it from the textbox but keeps the value in the hidden field, then when I go to add another item it appends it to the hidden field, so now there are two values in the hidden field but only one item in the textbox that can be removed.

    My setup is as follows:

    $("div.animal div.name input[type=text]").autoSuggest(

            minChars: 3,
            startText: "",
            selectedItemProp: "name",
            selectedValuesProp: "regCode",
            searchObjProps: "name",
            selectionLimit: 1,
            retrieveComplete: function(data) { return data.results; },
            selectionRemoved: function(elem) {
                elem.fadeTo("fast", 0, function() {


  4. 4 Posted by Chris Bruce on 09 Jun, 2010 04:51 PM

    Chris Bruce's Avatar

    Vadim's patch works great and fixes this bug. Thanks Vadim!

    I don't want to upload the full file as my configs are different. However, the clue for implementing Vadim's patch is in viewing the source when you click on the patch (or downloading the file to your desktop).

    You'll see @@ signs which indicate which line number the patch starts. You'll also see the following at the beginning of lines:

    • which indicates to remove this line
    • which indicates what to replace what you have just removed with If there are no - or + then those lines are just there for reference to help you see where you are and you just leave them.

    I hope this helps.

  5. 5 Posted by TJ McKenie on 22 Oct, 2010 03:48 AM

    TJ McKenie's Avatar

    I have noticed this same issue. It only happens with the very first selected item to the list. If you remove it from the list, the value is still stored in the hidden field and passed on submit.

  6. 6 Posted by mikeSM on 28 Oct, 2010 12:21 PM

    mikeSM's Avatar

    I noticed the same problem. When the form is submitted the first element passes on submit even if all previously selected elements was deleted. I noticed a related bug: for the first usage the autosuggest field suggests all available data for the first element and for the second element; then it retire selected element from the suggest list.

    Thanks for a this great plugin!

  7. 7 Posted by bigmartin on 02 Dec, 2010 11:07 AM

    bigmartin's Avatar

    patch works great, thx!

    you can reproduce it very simply:
    go to your page http://code.drewwilson.com/entry/autosuggest-jquery-plugin
    select some suggest in autocompleter
    delete this suggest with backspace
    inspect hidden field with firebug -> the entry is still there (see attachment)

  8. 8 Posted by Dan Brendstrup on 12 Jan, 2011 10:37 PM

    Dan Brendstrup's Avatar

    Sounds like the patch fixes this bug, but I wanted to stick with the packed version of the plugin, so this little hack will solve the problem as well:

    selectionRemoved: function(elem){
        if( $("li.as-selection-item").length == 0 ){
          $("input[type='hidden']").attr("value", "");

    Hoping for a new release soon that'll include this patch. Awesome plugin, btw!

  9. 9 Posted by Blake on 09 Feb, 2011 07:15 AM

    Blake's Avatar

    Here is the real fix, it works when you have multiple suggest boxes.

    selectionRemoved: function(elem) {

                elemHtml = elem.html();
                selectedVal = elemHtml.replace(/<a\b[^>]*>(.*?)<\/a>/i,"");
                parentID = elem.parent().attr('id');
                parentID_postfix = parentID.replace("as-selections-", "");
                currentVals = $('#as-values-'+parentID_postfix).val();
                finalVals = currentVals.replace(selectedVal+',', "");
  10. 10 Posted by pjack on 03 Jan, 2012 05:51 AM

    pjack's Avatar

    Just an FYI this patch is still relevant as of Jan 3, 2012 as there is no official fix yet and I was having the same issue.

  11. 11 Posted by DeadMan on 14 Mar, 2012 02:22 PM

    DeadMan's Avatar

    Yes. I too had same issue. After changing line no: 334
    from values_input.val(values_input.val().replace(","+data[opts.selectedValuesProp]+",",","));
    to values_input.val(values_input.val().replace(data[opts.selectedValuesProp] + ",", ""));
    it is working fine.

  12. 12 Posted by Ryan on 15 Mar, 2012 05:33 PM

    Ryan's Avatar

    Same deal here, I used Dan's fix for this.

  13. 13 Posted by jhsu on 23 Mar, 2012 01:41 PM

    jhsu's Avatar

    I had the same problem also - I have multiple autosuggest widgets on one page, and all of them can only have one thing assigned to it.

    Blake - your solution looks good for multiple autosuggest widgets on one page.

    selectionRemoved: function(elem){

    // remove the input value currently in 'as-values-<id autosuggest binded to>', 
    // as it doesn't always get removed using the delete key or by clicking the "x" inside the selection.   
    // parentId is 'as-selections-<id autosuggest binded to>', get the last part
    var indexLastDash = elem[0].parentNode.id.lastIndexOf('-');
    var id = elem[0].parentNode.id.substr(indexLastDash+1, elem[0].parentNode.id.length);
    // this only works because only 1 item can be assigned per widget
    $("[id^=as-values-" + id + "]").attr("value", "");


  14. 14 Posted by harold on 12 Nov, 2012 07:13 PM

    harold's Avatar

    deadman's fix worked for me... thanks so much

  15. 15 Posted by semiaddict on 20 Jan, 2013 07:04 PM

    semiaddict's Avatar

    deadman's patch worked for me too, but I also had to change line 168:

    values_input.val(values_input.val().replace(last + ",", ""));

    to make the delete button work as expected as well.

Reply to this discussion

Internal reply

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

Attaching KB article:


Already uploaded files

  • autosuggest.patch 1.44 KB

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