A potentially simple issue with jQuery UI autocomplete is stumping me. My source is
var ac = [
{
label: "One Thing",
value: "One-Thing"
},
{
label: "Two Thing",
value: "Two-Thing"
},
]
I am invoking the widget with
$(function() {
$( "#search" ).autocomplete({
source: PK.getAutocompleteSource(),
focus: function( event, ui ) {
$("#search").val(ui.item.label);
return false;
},
select: function( event, ui ) {
$("#search").val(ui.item.label);
PK.render(ui.item.value);
}
});
});
All works fine. When I type in the #search
input field, the matching label shows up in the dropdown, and when I select
the correct search is performed. The widget even shows the label
in the #search
input field as I select different items in the dropdown using the arrow keys (or the mouse). Except, soon as I hit enter, the widget fills the #search
input field with the value
instead of the label
. So the field shows One-Thing instead of One Thing.
How can I correct this? Surely what I am expecting is the more reasonable behavior, no?
event.preventDefault();
did the trick. Seriously, this should be in the docs. – Elva