Using AutoSuggest with Backbone (or anything that doesn't immediately render to the DOM)

Reman's Avatar

Reman

06 Jan, 2013 08:14 AM

I'm using AutoSuggest with Backbone.js, and I faced an issue where the dropdown wasn't showing up when I attached it to my input element. It turns out that this was because I was applying autosuggest before it hit the DOM:

$('input').autoSuggest(... options ..)

And then later:
$("#container").append( dom nodes that had the input element )

There were two lines in the AutoSuggest plugin code that assumed id's were already attached to the page, which I patched to make it work:

// FIX: var selections_holder = input.parents('#as-selections-'+x);
var org_li = input.parents('#as-original-'+x);
// Original: //var selections_holder = $("#as-selections-"+x); //var org_li = $("#as-original-"+x);

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