jQuery UI Autocomplete DownArrow UpArrow
Asked Answered
S

1

28

I am having some issues with jQuery Autocomplete and moving DownArrow and UpArrow ?

The problem seems to be that

<input id="autocomplete-input" value="">

focus: function (event, ui) {
       $('#autocomplete-input').val(ui.item.label);
 }

This works great for MOUSE focus - but when I use arrowUp and arrowDown - it selects the ui.item.id over and above the ui.item.label

How can I fix this so that either:

  1. the input val isn't changed at all [i.e. it keeps the users inputted term]
  2. it updates the input val with the focused val the user is on with keydown/keyup

thanks

Stigmatism answered 8/11, 2011 at 3:58 Comment(0)
F
60

Make sure to prevent the default behavior of the focus event:

focus: function (event, ui) {
    this.value = ui.item.label;
      // or $('#autocomplete-input').val(ui.item.label);

    // Prevent the default focus behavior.
    event.preventDefault();
      // or return false;
}
Farrago answered 8/11, 2011 at 4:9 Comment(2)
aha! awesome thanks so much @andrew - i totally forgot to try that :)Stigmatism
This is working but one issue when key(up/down) is at selected item text box is showing value not label but after pressing enter its again showing valueKeratosis

© 2022 - 2024 — McMap. All rights reserved.