4

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();
}
Andrus
  • 26,339
  • 60
  • 204
  • 378

1 Answers1

2

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.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thank you. Excellent. I added this patch. Maybe it is better to move this line inside if in `if (e.keyCode === 27) { $($t).jqGrid("restoreRow", rowid, afterrestorefunc); e.stopPropagation(); }` to block esc key propagation. Btw. have you looked to the issue described in http://stackoverflow.com/questions/7558869/how-to-show-autocomplete-field-value-in-form-editing – Andrus Sep 27 '11 at 18:16
  • @Andrus: Yes! It sounds good. Just try this, but I think you are right. Last time I had less free time, so I posted less answers as before on the stackoverflow. I hope at the end of the week I will have more time. – Oleg Sep 27 '11 at 19:04
  • @Andrus: By the way, I spend many time in working on the new jqGrid feature: multi-rows column header (groups of column headers) see [the demo](http://www.ok-soft-gmbh.com/jqGrid/SimpleLocalGridHeadersWithFirstRow4.htm) from [the answer](http://stackoverflow.com/questions/7341339/jqgrid-column-group/7351638#7351638). The work is still not finished, but I am sure that in the next version of jqGrid, which will be published in about 10 days, will be the multi-header feature (groups of column headers) in some form. – Oleg Sep 27 '11 at 19:15
  • thank you. Will patch from this answer also included in next release of jqGrid? I havent seen any information about next release date. It is interesting that e.stopPropagation() enables IE9 default Ctrl+S behaviour (save dialog). It should disable Ctrl+S completely. – Andrus Sep 28 '11 at 06:13
  • 1
    @Andrus: You can read about the new release [here](https://github.com/tonytomov/jqGrid/commit/d2648c048a04571677eb86132ea3ddd0899afb15#commitcomment-613764). To have patches like with `stopPropagation` you should post bug report in the trirand forum. – Oleg Sep 28 '11 at 07:39
  • Thank you. I posted it in http://www.trirand.com/blog/?page_id=393/bugs/keyboard-shortcuts-are-not-working-in-inline-edit-can-oleg-patch-applied/ . Thank for the git link. I found from this code which allows to add and edit file data in jqgrid with other row data. Is it reasonable to use this or is http://tpeczek.blogspot.com/2011/03/jqgrid-and-aspnet-mvc-form-editing-with.html upload method better? – Andrus Sep 28 '11 at 11:28