Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass source in callback? #2

Open
mattcheah opened this issue Nov 17, 2015 · 2 comments
Open

How to pass source in callback? #2

mattcheah opened this issue Nov 17, 2015 · 2 comments

Comments

@mattcheah
Copy link

Hi, Thanks for creating this widget - it's really useful.

I've been trying to use multisearch with ajax to get the source list of searchable items from a database, but I cannot figure out how to create pass that list back to the source. This is my code:

$("#item-search").multisearch({
  source: function (term, callback) {
    $.ajax({
            type: 'POST',
            url: url,
            data: {term:term},
        })
        .done(function(data) {
            //console.log(data) -> ["item1","item2", "item3", "etc"]
            callback(data); //similar to how you do it in line 180 here: bseth99.github.io/jquery-ui-multisearch/examples/movies.html
        })
  });

Currently the picker shows 5 "undefined"s regardless of how many results are returned.
Let me know if there's something I'm missing. Thanks!

@bseth99
Copy link
Owner

bseth99 commented Dec 15, 2015

Try passing an array of hashes - { id: 1, name: 'item1' }. id can be the same as name. This can all be overridden, but the default behavior expects that format.

@mattcheah
Copy link
Author

it worked! thanks so much for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants