How to catch keyboard keys if jqueryUI datepicker is active

In the column

jqgrid contains the jqueryUI DataPicker, which is used in built-in editing mode. If the DataPicker input element has focus and Ctrl + S or some other key is pressed, body_onkeydown is not executed: IE9 calls the default behavior of ctrl + s (save dialog). In FireFox, body_onkeydown also fails.

How to fix this code so that the keys can catch if DatePicker has focus?

DatePicker is defined as:

$(elem).datepicker({ dateFormat: 'dd.mm.yy', autoSize: true, showOn: 'button', changeYear: true, changeMonth: true, showButtonPanel: true, showWeek: true }); 

Code used to capture the ctrl + s key:

 $(function () { $("html").keydown(body_onkeydown); }); function body_onkeydown(evt) { // Why this function is not executed if datepicker has focus? if (evt.ctrlKey) { switch (evt.keyCode) { case 83: $("#grid_savebutton").click(); break; } cancel(evt); return false; } function cancel(evt) { evt.returnValue = false; evt.keyCode = 0; evt.cancelBubble = true; evt.preventDefault(); evt.stopPropagation(); } 
+4
source share
1 answer

That's a good question! In jqGrid code, you can at some point return false or stopPropagation inside event handlers, which I personally consider unnecessary. In your case, the problem is line 8237 from jquery.jqGrid.src.js (in version 4.1.2) or line 87 grid.inlinedit.js (see here ):

 e.stopPropagation(); 

If you comment on this, inline editing will no longer stop the distribution of the keydown event keydown and as you might see in the demo, it can catch Ctrl + S during inline editing.

+2
source

All Articles