Is it somehow possible to set a value (value/text as in a combobox) in jQuery UI Autocomplete?
I need to get a DB id from the selected item in the Autocomplete box.
Thanks in advance!
You really can't, at least as far as I've seen, set a value in the jQueryUI autocomplete widget, but you can use the widget to set the value of an attribute in a hidden field or maybe an attribute on some other element.
Here's a quick jsFiddle I put together to demostrate it. Hopefully this can help.
My example is based on the jQueryUI AutoComplete example for "Custom Data and Display". Basically, it assumes you get some array of data back from a service or it's rendered from the server-side. In your array of data, you have a display field, a key value and your DB ID. The key value really isn't necessary. But when you select an item in your autocomplete list, you can capture what was selected in the autocomplete's select
event and then handle the data appropriately. I stored the 'id' value in my array in a hidden field, but you can handle it differently.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With