javascript - Autocomplete not firing on first input -



javascript - Autocomplete not firing on first input -

so i've googled, searched here, went everywhere, , can't find answer. i'm using jquery ui autocomplete search list of item ids numbers. can length 1 - 99999.

the issue:

when type '2' example, nil happens, nail backspace , type '2' 1 time again , time, starting 2 appears below, , event shows in "network list" on developer's tools. furthermore, when search 1, 1 shows up, it's not performing search it's spitting input value. when nail backspace , type in 1 again, search fires , same results did 2. no matter number type should fire default shouldn't it? how right , autocomplete working properly.

code:

$('.item-inventory').on('keyup', '#item_num', function(){ //var search = $(this); var itemname; var itemprice; var itemdesc; $(this).autocomplete({ delay : 100, source: function(request, response){ $.ajax({ url: '../assets/server/orders/item_search.php', datatype: 'json', data: {search: request.term}, success: function (data){ var keys = data.search; // $('#item-name').val(data.search[0].item); // itemprice = data.search[0].price; // itemdesc = data.search[0].desc; response($.map( keys, function(i){ return{ label : i.id }; })); } }); }, minlength : 1 }); //$('#item-search-results').removeclass('hidden'); $(this).on('autocompleteselect', function(event, ui){ $('#item-search-results').removeclass('hidden'); }); });

basically connecting autocomplete after first keypress (which late first keypress). reconnecting on every keypress.

you need connect autocomplete 1 time @ startup relevant element.

e.g. place outside of key handler:

$('.item-inventory #item_num').autocomplete({ delay : 100, source: function(request, response){ $.ajax({ url: '../assets/server/orders/item_search.php', datatype: 'json', data: {search: request.term}, success: function (data){ var keys = data.search; // $('#item-name').val(data.search[0].item); // itemprice = data.search[0].price; // itemdesc = data.search[0].desc; response($.map( keys, function(i){ return{ label : i.id }; })); } }); }, minlength : 1 });

javascript jquery autocomplete

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -