bug: first record can be added twice

Asbjørn Morell's Avatar

Asbjørn Morell

31 Jul, 2010 12:44 PM


Thanks for this great plugin. There is a small bug:

If you refresh the page http://code.drewwilson.com/entry/autosuggest-jquery-plugin (hold down shift to clear cache) the demo field will allow you to add the first selected record twice. If I remove the selected fields I can't reproduce the problem before the page is refreshed/cache cleared again.

Hope I have posted in the right place.

  1. 1 Posted by philip on 01 Sep, 2010 02:18 PM

    philip's Avatar

    Here is a way to fix it:

    Change line 275


    if(str.search(query) != -1 && values_input.val().search(","+data[num][opts.selectedValuesProp]+",") == -1){


    if(str.search(query) != -1 && (','+values_input.val()+',').search(","+data[num][opts.selectedValuesProp]+",") == -1){

    Hope this helps ;)


  2. 2 Posted by philip on 01 Sep, 2010 05:01 PM

    philip's Avatar

    This post complements the previous:

    Add a line after line 326

    function add_selected_item(data, num){

    function add_selected_item(data, num){
    if (values_input.val().indexOf(",")==-1) addinstr=','; else addinstr='';


  3. 3 Posted by philip on 01 Sep, 2010 05:03 PM

    philip's Avatar

    Line 326

    function add_selected_item(data, num){
    if (values_input.val().indexOf(",")==-1) addinstr=','; else addinstr='';

    I forgot the last changing line.

    Sorry :)

  4. 4 Posted by Lakhats on 02 Sep, 2010 06:25 PM

    Lakhats's Avatar

    Thanks philip... Its working now...

  5. 5 Posted by Asbjørn Morell on 24 Oct, 2010 10:11 PM

    Asbjørn Morell's Avatar


    You fixed seems to have created a new bug. I can't create a duplicate record any more, however something get's messed up if I add two users, remove them and try to add them again. The last laser won't show up any more...

  6. 6 Posted by Blake on 09 Feb, 2011 07:13 AM

    Blake's Avatar

    add this to line #46

    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+',', "");
  7. 7 Posted by Joe Mocker on 02 Sep, 2011 06:18 PM

    Joe Mocker's Avatar

    Ahh. Great fix. That was bugging the heck out of me.

Reply to this discussion

Internal reply

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

Attaching KB article:


Already uploaded files

  • screen-capture-32.png 39.6 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