How to check if jqueryUI autocomplete open panel was open

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?

+6
source share
2 answers

Andru comment directly on. If you stop extending the event after autocomplete completes, it resets the ESC

 $('.autocomplete').bind('autocompleteclose', function(event, ui) { return false; }); 
0
source

Using:

 !!$($('autocompleteselector').autocomplete('widget')).is(':visible') 

.. to check for specific autocomplete.

To check if a drop-down menu is open:

 !!$('.ui-autocomplete.ui-widget:visible').length 
+13
source

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


All Articles