Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery auto complete, change event not working 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", "")});

The majority of this works perfectly, however, it seems that when the field is changed the 'change' event is not always triggered.

When selecting an element from the list, it works fine, however if you delete the values in the box using the backspace (delete) key, and then click off the text box, the change event is only sometimes called. Is there something I'm missing?.. It seems to only not be called when values are deleted manually.

Regards, Josh

like image 646
Joshua Avatar asked Jan 27 '15 11:01

Joshua


1 Answers

This is alternative clean solution

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

This answer copied from here

like image 182
Faruk Omar Avatar answered Oct 18 '22 08:10

Faruk Omar