FrancisMarfo
FrancisMarfo

Reputation: 143

JqueryUI autocomplete returns wrong item on focus


I used JqueryUI on this project im working on.
When I focus on the next item in the list with the down arrow key, jqueryui returns the previous selected item

Here's a perfect working sample is here on jsFiddle

Here's the Jquery code

$( "#itemname" ).autocomplete({
    source: function( request, response ) {
            var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
            response( $.grep( tags, function( item ){
                return matcher.test( item );
            }) );
        }, 
        //focus: function(event) { alert( event.type ); }
        focus : function(event, ui) { 
            //alert( $(this).val() );
            var item_name_this = $(this).val();
            $('#properties_item_name').html(item_name_this);               
        }
});

Upvotes: 2

Views: 165

Answers (1)

Adil Shaikh
Adil Shaikh

Reputation: 44740

focus: function (event, ui) {
     var item_name_this = ui.item.value;
     $('#properties_item_name').html(item_name_this);
}

Demo --> http://jsfiddle.net/VCd4J/16/

Upvotes: 5

Related Questions