With jquery autocomplete widgets how to fill input value after selection using my own data

The json form text input line returned by the autocomplete widget will be [{id = 1, lable = "lable1"}, ......]

[{id = 1,label="label1"},{id = 2, label="label2"},......]

and I want the displayed value of the input field to be a "label", which works by default, but I want the input value to be "id" when I submit the form.

Many thanks!

+1
source share
1 answer

I usually save <input type = 'hidden'> next to the autocomplete input, and then in the event of the selection of full completion, which is with an identifier:

 $("#autocomplete-input").autocomplete({
            minLength: 2,
            select: function (event, ui) {
                $("#autocomplete-input-id").val(ui.item.id);
            }

        }); 
0
source

All Articles