Potential Bug when using more than one autoSuggest on a page

Gaurav's Avatar

Gaurav

05 Feb, 2011 01:07 AM

I've set up two text boxes on one page to use autoSuggest. The first autoSuggest instance is set up before the second one (the second one loads only if a particular dialog is opened). We are using the atHtmlID option to distinguish the two autoSuggest boxes.

  • autoSuggest box 1 works fine if autoSuggest box 2 is never initialized.
  • autoSuggest box 2 works fine when it is initialized
  • after autoSuggest box 2 is initialized, the search for autoSuggest box 1 continues to work, but when a search result is selected, it does not get added to the input area nor does the value get set in the hidden values_input input element.

Debugging this, I've found that in jquery.autoSuggest.js (v1.4) around line 301 $.fn.autoSuggest.add_selected_item() is called to add a search result that has just been selected to the input text box. This is where I think the bug is. Before the call, global variables such as 'value_input' and 'org_li' have the correct values (they point to autoSuggest box 1 elements). When $.fn.autoSuggest.add_selected_item() is called, these same global variables have a different context - they are pointing to autoSuggest box 2 elements. That's why the selected element does not make it into autoSuggest box 1 - it is actually being put into autoSuggest box 2, which is hidden off the page.

It looks like either the initialization of autoSuggest box 2 is overwriting the $.fn.autoSuggest.add_selected_item() function affiliated with autoSuggest box 1 or there are two $.fn.autoSuggest.add_selected_item() functions in global space and the one for autoSuggest box 2 is being called since it was the last initiated.

By creating a copy of $.fn.autoSuggest.add_selected_item(), but making it private, both autoSuggest box 1 and 2 work just fine.

We really need to be able to run multiple autoSuggest boxes in our system and any pointers to what we may be doing wrong or a fix for this bug would be greatly appreciated.

Thanks,
Gaurav Bhatnagar
UI Developer
Sakai OAE http://www.sakaiproject.org/welcome-sakai-oae

  1. 1 Posted by Xnuiem on 22 Mar, 2011 09:54 PM

    Xnuiem's Avatar

    We fixed this by adding

    results_ul.show();

    after every instance of results_holder.show();

    For us, the results were updating correctly, just not showing.go

  2. 2 Posted by Jamie on 28 Nov, 2011 06:07 PM

    Jamie's Avatar

    I came across this web page because I’m having the same problem. Making add_selected_item() private (i.e. just a normal-looking function) does indeed fix the problem, but as I need to programatically add items to the box it was no good for me.

    I’m using my autosuggest instances in ‘open’ and ‘save’ dialog boxes and I’ve got round the problem by creating a new instance each time the dialog is opened.

  3. 3 Posted by umesh Kumar Ahe... on 30 Nov, 2011 11:52 AM

    umesh Kumar Aherwal's Avatar

    needs help in urgent version 1.4, is still shows options in the list even, if we select form the list, ie option list must not have last selected option. Please note this happens only for the first time .

  4. 4 Posted by umeshkumar aher... on 17 Mar, 2012 06:40 PM

    umeshkumar aherwal's Avatar

    Hello Drew,
    I am facing same issue with multiple instances .. if i have more than 4 it fails to recognize which auto suggest is activated it. and opens dropdown in some other auto suggest.

  5. 5 Posted by umesh kumar Ahe... on 19 Mar, 2012 07:10 AM

    umesh kumar Aherwal's Avatar

    Hello Drew,
    I think I was calling it wrong that cause, perhaps the random generation a conflict.
    Thanks.

  6. 6 Posted by Hello Drew on 21 Mar, 2012 12:17 AM

    Hello Drew's Avatar

    Its resolved, issue was dynamic creation of the auto suggest, which called the auto suggest script more than once with a high probability of clashing with random number generated earlier call.

  7. 7 Posted by Mikey on 30 Apr, 2012 01:12 AM

    Mikey's Avatar

    @umeshkumar aherwal

    How did you resolve your issue ---> "needs help in urgent version 1.4, is still shows options in the list even, if we select form the list, ie option list must not have last selected option. Please note this happens only for the first time ."

    I am having the same problem.

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

Generic

? 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