#8394 closed bug (notabug)
focus of autocomplete items sources item value instead of label for source items
Reported by: | jimmont | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 1.9.0 |
Component: | ui.autocomplete | Version: | 1.8.21 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
When the autocomplete source uses a list of items that have different label and value pairs, as I interact with the autocomplete listing, the UI fills the selected field with the item.value instead of the desired item.label. For example, an item has the label: "apples", and the value: "123". When I walk through the options this item shows "123" in the UI instead of "apples".
Reproducible in 1.8.21 and 1.8.16. Thinking it might affect all versions.
Change History (5)
comment:1 Changed 11 years ago by
comment:2 Changed 11 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
This is working as intended. If you need more data, for example an id to put into a hidden field, you should use other properties instead. The data you provide to autocomplete can have any properties, only value
and label
are used by autocomplete. You could also cancel the focus and select events to implement custom behaviour.
comment:3 Changed 11 years ago by
For more background on this, go look at existing autocomplete implementations and you'll notice this is the behavior that they have. The easiest way to see this is to start typing in any URL in your browser's location bar.
comment:4 Changed 11 years ago by
Component: | ui.core → ui.autocomplete |
---|
comment:5 Changed 11 years ago by
reading the doc more closely I see the detail called out: http://jqueryui.com/demos/autocomplete/
The data from local data, a url or a callback can come in two variants: ... An Array of Objects with label and value properties: [ { label: "Choice1", value: "value1" }, ... ] The label property is displayed in the suggestion menu. The value will be inserted into the input element after the user selected something
submitted pull request with potential fix: https://github.com/jquery/jquery-ui/pull/678