trevoreyre / autocomplete

Accessible autocomplete component for vanilla JavaScript and Vue.
https://autocomplete.trevoreyre.com
MIT License
428 stars 75 forks source link

Set value result and value input #135

Open maatheeus opened 2 years ago

maatheeus commented 2 years ago

It's possible set value input and other value to label.

{"id":1, "name":"xpto"}

I need submit value id and show value name in search.

In js component

didiosn commented 2 years ago

you found a way ?

maatheeus commented 2 years ago

Hi, Yes

<div id="autocomplete_exams" class="autocomplete">
        <input class="autocomplete-input" />
        <ul class="autocomplete-result-list"></ul>
        <ul id="no-results" class="autocomplete-result-list" visible="false"></ul>
 </div>
<input type="hidden" name="value_id" id="value_id">

Use hidden input to store the id value. Also use onchange in select to update the hidden input value