Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Autocomplete selected value

I have a autocomplete on the page using jQuery UI and here is the JSON:

[ {"label":"test1", "value":"1"},
  {"label":"testtest", "value":"6"},
  {"label":"test2", "value":"8"} ]

The default action of autocomplete will grab the value of the item and place into the input box. Is there a way I can stop it? Instead have two separate actions: one inject to a hidden box (with value) and the other to the input box with (label).

$.getJSON('index.php?controller=account&action=getusers', function(data) {
    tempJson = data;

    $(".auto-search").autocomplete({
        minLength: 2,
        dataType: 'json',
        source: tempJson,
        select: function (event,ui) {
            $('input[name="user-id"]').val(ui.item.value);
        }
    });
});
like image 934
Bill Avatar asked Feb 04 '26 06:02

Bill


1 Answers

Do you mean something like:

........
select: function (event,ui){
    $('input[name="user-id"]').val(ui.item.label);
    $('input[name="your-hidden-field"]').val(ui.item.value);
    return false;
}
like image 61
Sudhir Bastakoti Avatar answered Feb 05 '26 21:02

Sudhir Bastakoti