hlsolutions / jquery-autosuggest

An AutoSuggest jQuery plugin.
http://hlsolutions.github.io/jquery-autosuggest/
GNU General Public License v2.0
15 stars 3 forks source link

Add new item with add method #32

Closed luiscarlostic closed 10 years ago

luiscarlostic commented 10 years ago

Hello, how can add a item with your methods

add Arguments: data or array of data Example 1:

$('#myinput').autoSuggest('add', {
  value : 4711, name : 'Mick Jagger'
})

Example 2:

$('#myinput').autoSuggest('add', {
  value : 4711, name : 'Mick Jagger'
}, {
 value : 4712, name : 'Kelly Slater'
})

I try this and nothing happen. Can you help me please.

knalli commented 10 years ago

How does your init/setup look like?

luiscarlostic commented 10 years ago

Just like this:

var data = [
                    {value : 21, name : "Mick"},
                    {value : 43, name : "Johnny"},
                    {value : 46, name : "Richard"},
                    {value : 54, name : "Kelly"},
                    {value : 55, name : "Rudy"},
                    {value : 79, name : "Michael"}
                ];
var options = {
                    selectedItemProp : "name",
                    searchObjProps : "name",
                    fadeOut : 'slow',
                    retrieveLimit  : 3,
                    selectionLimit : 1,
                    canGenerateNewSelections :false,
                    startText : 'Buscar',
                    emptyText : '<strong>{0}</strong> no arrojó resultados.',
                    limitText : 'No se permiten mas selecciones',
                    showResultListWhenNoMatch : true
                };
            $("#myinput").autoSuggest(data, options);
knalli commented 10 years ago

Please have a look at this, I've added a sample for this: da8a57f1948ca139401656b83fb59352b7750727

luiscarlostic commented 10 years ago

Ty for the sample, help too much.

luiscarlostic commented 10 years ago

Ok I finally make it work, I was selecting in a wrong way my input. This is my code.

    var input = $('.as-selections').find('input[type=text]');
    input.autoSuggest('add', {value : "55", name : "Rudy Hamilton"});