Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery UI autocomplete input - How to check if input is empty on change?

I have a Jquery UI auto complete field on my page, and I need to do something when input becomes empty (i.e The user typed something in, then deleted all of it).

This event must fire regardless of whether what they typed in initially produced autocomplete results.

The point is to show a button if there are no autocomplete results for typed entry, and remove it if there are results OR the input is empty.

UPDATE I have tried this...

$('#employeeAutocomplete').change(function() {
     alert("eventFired");
     if($( "#employeeAutocomplete" ).val() == ''){
         $('#createEmployeeBtn').hide();
     }
});

And alert is not displayed....

Thanks, Danny

like image 600
Danny Avatar asked Jul 27 '11 21:07

Danny


1 Answers

http://forum.jquery.com/topic/autocomplete-and-change-event

About the same problem:

I've found the change: does work, but only when the input loses focus.

The solution I implemented, to get the effect I desired was to implement my own check as part of the source: function. I set minLength: to 0, and if the length was less than 2 I loaded my default display data.

like image 103
niklasdstrom Avatar answered Oct 31 '22 04:10

niklasdstrom