[PATCH] Include data with selectionAdded(elem) callback?

Doug Mayer's Avatar

Doug Mayer

06 Dec, 2010 03:55 AM

When one wants to use AutoSuggest throughout their project, but sometimes would rather manipulate the DOM some way other than adding a token, you can use the selectionAdded callback to immediately remove the element, but you don't have a way to get at the data related to the selected element.

Could you change the selectionAdded callback method signature from:

function (elem)

to:

function (elem, data)

This simple might save someone else some headache and be a good addition to the project, unless you know of a better way to do this?

  1. 1 Posted by Doug Mayer on 06 Dec, 2010 03:58 AM

    Doug Mayer's Avatar

    Sorry, I opted out of providing a patch file because I didn't have an original handy and forgot to change the title. It's just a 2-liner though (default settings and adding ", data" where selectionAdded is called).

  2. 2 Posted by Dan Haywood on 10 Dec, 2010 05:50 AM

    Dan Haywood's Avatar

    Good call - it is useful, in some situations to remove the selection immediately... as Doug says... defaults selectionAdded: function(elem, data){} - for my purposes I passed through the raw data to access the associated value...

    add_selected_item(raw_data, data, number);

    function add_selected_item(raw_data, data, num){
    ..... (the existing code).. org_li.before(item.html(data[opts.selectedItemProp]).prepend(close));

    opts.selectionAdded.call(this, org_li.prev(),raw_data);
                }
    

    Good call Doug

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