bseth99/jquery-ui-multisearch

How to pass source in callback?

mattcheah opened this issue · 2 comments

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!

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.

it worked! thanks so much for your help!