Minor bug: first selected item is ignored on subsequent searches

Brad Flood's Avatar

Brad Flood

27 Apr, 2010 09:38 PM


This is the best 'autosuggest/complete' plugin I've found. Great work!

I found a minor bug with line 275. The first selected item is ignored when searching for the search string in the stored values of the current selected items.

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

I have resolved the issue by prepending a comma to the string of values already selected:
var currentValues = "," + values_input.val(); if (str.search(query) != -1 && currentValues.search("," + data[num][opts.selectedValuesProp] + ",") == -1) {

This may not be the most elegant solution...but it works.

Excellent plugin. Thanks

  1. 1 Posted by Brad Flood on 28 Apr, 2010 03:30 PM

    Brad Flood's Avatar

    Same problem occurs with deletion.

    Line 168 and 334 do not remove the first item. Using the same technique above...

    Replacing line 168 values_input.val(values_input.val().replace(","+last+",",","));
    var currentValues = "," + values_input.val(); values_input.val(currentValues.replace("," + last + ",", ","));

    Replacing line 334 values_input.val(values_input.val().replace(","+data[opts.selectedValuesProp]+",",","));
    with var currentValues = "," + values_input.val(); values_input.val(currentValues.replace("," + data[opts.selectedValuesProp] + ",", ","));

    Resolves the deletion issue.

  2. 2 Posted by Alexander Nenko... on 04 Jul, 2011 02:21 PM

    Alexander Nenkov's Avatar

    The above solutions add too many comas and this might cause problem with further processing. Resolved it using the following
    Line 168:
    values_input.val(values_input.val().replace(last+",","")); Line 275:
    if(str.search(query) != -1 && values_input.val().search(data[num][opts.selectedValuesProp]+",") == -1){ Line 334:

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