Search and Top Navigation
#7483 closed bug (notabug)
Opened June 16, 2011 09:49AM UTC
Closed June 16, 2011 12:21PM UTC
Last modified June 16, 2011 01:18PM UTC
autocomplete when moving up/down in the list item's label should be selected in the edit box instead of item's value
Reported by: | berdeter | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 1.9.0 |
Component: | ui.core | Version: | 1.8.13 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Let's say we filled in the autocomplete collection with items not having value and label identical.
U types a few letters
S shows a list of labels matching the typed letters (fine)
U presses keydown.
S highlights the next element in the list (fine)
S replaces the word typed by U by the value (bug)
U presses the return key. Nothing happens ! (bug)
The end user hasn't to now anything about the value of the item. This concept should be hidden to him. Worse the control fails to select the item when the value is in the edit box. To fix this (I'll do the fork) :
.menu({ focus: function( event, ui ) { var item = ui.item.data( "item.autocomplete" ); if ( false !== self._trigger( "focus", event, { item: item } ) ) { //BDT (NSI) Fixing autocomplete lib. The element value should be set to item's label instead of item's value // use label to match what will end up in the input, if it was a key event if ( /^key/.test(event.originalEvent.type) ) { self.element.val( item.label ); } } },
This is as intended. There are two common scenarios where the label and value are different: 1) You want to display something more descriptive in the menu, but are fine displaying the raw value in the text field; 2) You want to do completely custom handling of the actual values and have custom displays even for the text field. What you want is completely custom handling. You clearly don't want the label being submitted, so you have to be doing something custom already anyway. See the custom data and display demo to see how to do what you want.