Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autocomplete.js is not working with keyboard up and down arrow keys

I am using the following jquery ui autocomplete function. This is working perfectly with mouse but by keyboard, I am not able to select any value. Have a look at the code.

$("#"+textBoxId).autocomplete("../common
   /autoSuggestValues.php?index="+index+"&
  randValue="+Math.random(), {
    selectFirst: false,
    width:textBoxWidth,
    minChars: 2,
    autoFill: false,
    scroll: true,
    scrollHeight: 120,
    formatItem: function (rowdata) {
        var details = rowdata[0].split('@#@');
        return details[0];
    }
});

$('#'+textBoxId).result(function (event, data, formatted) { 
    var det   =  data[0].split("@#@");
    if(det[0] != 'No Match Found') {
        $('#'+textBoxId).val($.trim(det[0])).css('border','');  
        $('#'+hiddenId).val(det[1]);
        processAutoSuggOptFunc(optionalFunction); //process the optional  
     function using the another built function "processAutoSuggOptFunc"
    } else {
        $('#'+textBoxId).val('');   
        $('#'+hiddenId).val('');    
    }
});
like image 715
Manish Jangir Avatar asked Nov 01 '12 10:11

Manish Jangir


People also ask

How do I know if autocomplete dropdown is open?

If autocomplete dropdown is open, Esc press shoult perform its default action only (closing dropdown and cancelling selection). How to check if autocomplete dropdown was opened ? It can check for any autocomplete box was opened in document body.

How does jQuery autocomplete work?

In the process of searching a specific value, the jQuery UI autocomplete selection feature provides the user with some string suggestions for the input area which effectively saves time. The autocomplete select action is triggered when the user selects one of the options from the pre-populated list.

What is JS autocomplete?

The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are tags for programming languages, give "ja" (for Java or JavaScript) a try. The datasource is a simple JavaScript array, provided to the widget using the source-option. 1.


1 Answers

For me, providing the focus method made the solution: searchField.autocomplete({ ... focus: function (event, ui) { event.preventDefault(); jQuery(this).val(ui.item.suggestion); }, ... });

See also here: http://yuji.wordpress.com/2011/09/22/jquery-ui-autocomplete-focus-event-via-keyboard-clears-input-content/

like image 52
Thomas Avatar answered Oct 02 '22 23:10

Thomas