开发者

How to catch keyboard keys if jqueryUI datepicker is active

jqgrid column contains jqueryUI DataPicker used in inline edit mode. If DataPicker input element has focus and Ctrl+S or some other key is is pressed, body_onkeydown is not executed: IE9 invokes ctrl+s default behaviour (save dialog). In FireFox body_onkeydown is also not executed.

How to fix this code so keys can catched 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 catch ctrl+s keypress is:开发者_如何学编程

$(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();
}


It's a good question! In the code of jqGrid you can fine sometime return false or stopPropagation inside of event handles which I personally find unneeded. In your case the problem make the line 8237 of the jquery.jqGrid.src.js (in version 4.1.2) or the line 87 of the grid.inlinedit.js (see here):

e.stopPropagation();

If you comment the like the inline editing will not more stop propagation of the keydown event and how you could see on the demo you will be able to catch Ctrl+S during inline editing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜