The jQgrid form contains several jQueryUI autocomplete blocks.
In the keydown event handler, pressing the Esc key should only be processed if the autocomplete drop-down list is not open. If the autocomplete drop-down list is open, Esc press the shoult button to perform only the default action (closing the drop-down menu and deselecting).
How to check if an autocomplete popup was open? He can verify that the autocomplete window was open in the body of the document.
jQuery.extend(jQuery.jgrid.edit, { beforeShowForm: function ($form) { var gridIdEncoded = $.jgrid.jqID($form[0].id.substring(8)); $("#editmod" + gridIdEncoded).bind('keydown.formEvent', function (e) { if (e.which === 27) { // Todo: How invoke click only if any autocomplete dropdown is not opened $("#TblGrid_" + gridIdEncoded + "_2 #cData").trigger("click"); return false; } }); } });
Update
I tried to answer Dr. Mollet using
if (e.which === 27) { alert( $('.ui-autocomplete.ui-widget:visible').length ); if ( $('.ui-autocomplete.ui-widget:visible').length != 0 ) // dropdown is open, allow default behaviour return;
but $ ('. ui-autocomplete.ui-widget: visible'). length is 0 if esc is pressed (this is 1 if another key is pressed and the drop-down menu is open). It seems that the reason Esc causes the default autocompletion reason, first closes the drop-down list. Only after that, my handler is executable, which does not detect that the dropdown menu is complete.
How to fix it?
source share