JQuery auto complete, change event does not work as expected

Good morning,

I have the following code:

$("#close-request-field-clinic").autocomplete({ source: arrayClinic, delay: 0, minLength: 0, isDivider: function( item ) { return false; }, focus: function ( event, ui ) { $('#close-request-field-clinic').val( ui.item.label ); return false; }, select: function( event, ui ) { $('#close-request-field-clinic').val( ui.item.label ); if(ui.item.value == -1) { resetField('#close-request-field-clinic', false); } else { successField('#close-request-field-clinic'); setKey(finalValues, 'clinic', ui.item.value); if(msieversion()) { $(this).blur(); } } checkValidation(fieldCheck,'#close-request-personal-information-next'); return false; }, change: function( event, ui ) { alert('change'); if(!ui.item) { resetField('#close-request-field-clinic', false); removeKey(finalValues, 'clinic'); } checkValidation(fieldCheck,'#close-request-personal-information-next'); return false; } }).focus(function(){$(this).autocomplete("search", "")}); 

In most cases, this works great, however, it seems that when the field changes, the "change" event does not always fire.

When selecting an item from the list, it works fine, however, if you delete the values ​​in the field using the backspace (delete) key, and then click on the text field, the change event will be < sometimes . Is there something that I am missing? .. It seems that it is not called when the values ​​are deleted manually.

Regards, Josh

+5
source share
1 answer

This is an alternative clean solution.

 $("#close-request-field-clinic").on("autocompletechange", function(event,ui) { alert($(this).val()); }); 

This answer is copied from here.

+6
source

Source: https://habr.com/ru/post/1211991/


All Articles