jqgrid edit and add forms coontain textareas which can edited and enter adds new line to them.
How to allow Ctrl+S to save edit and add forms, just like clicking to save button in those forms ?
For inline edit I was able to add Save button to jqgrid toolbar and use
case 83: $("#grid_savebutton").click(); break;
In body onkeydown event to simulate pressing to this button by Ctrl+S
How to allow also to save in edit and add forms by Ctrl+S ?
Update
I added code
case 83: saveb = $("#TblGrid_" + "grid"+ "_2 #sData");
if (saveb.length > 0 ) {
evt.stopPropagation();
return;
}
$("#grid_savebutton").click();
break;
to body onkeydown handler. After first edit form open this code finds always that sData button exists and goes not invoke grid_savebutton anymore. It looks like sData button exists even if edit/add form is closed. How to fix it so that if edit/add form is not open, $("#grid_savebutton").click() is executed ?
Update2
keydown bindings used:
jQuery.extend(jQuery.jgrid.edit, {
savekey: [true, 13],
recreateForm: true,
closeOnEscape: true,
reloadAfterSubmit: false,
beforeShowForm: function ($form) {
var gridIdEncoded = $.jgrid.jqID($form[0].id.substring(8));
$("#editmod" + gridIdEncoded).bind( 'keydown', beforeShowFormHandler);
},
onClose: function () {
var gridIdEncoded = 'grid'; // $.jgrid.jqID($form[0].id.substring(8));
$("#editmod" + gridIdEncoded).unbind( 'keydown', beforeShowFormHandler);
}
});
var beforeShowFormHandler = function (e) {
var gridIdEncoded = 'grid';
if (e.ctrlKey && e.which === 83) { // 83 - 's'
$("#TblGrid_" + gridIdEncoded + "_2 #sData").trigger("click");
return false;
}
};
global keydown binding:
$(function () {
$("html").keydown(body_onkeydown);
});
function body_onkeydown(evt) {
var saveb;
if (evt.ctrlKey) {
switch (evt.keyCode) {
case 83:
saveb = $("#TblGrid_" + "grid" + "_2 #sData");
// todo: saveb.length > 0 is always true after form is opened first time:
if (saveb.length > 0) return;
$("#grid_savebutton").click(); break;
}
cancel(evt);
return false;
}
}
function cancel(evt) {
evt.returnValue = false;
evt.keyCode = 0;
evt.cancelBubble = true;
evt.preventDefault();
evt.stopPropagation();
}
Update3
TinyMCE html editor is attached to textarea elemnts in form in afterShowForm event using
$('.htmleditor', formSelector).attr('cols', '50').attr('rows', '15').tinymce({
theme: "advanced",
language: "et",
theme_advanced_buttons2: "",
theme_advanced_buttons3: "",
theme_advanced_buttons1: "bold,italic,underline,strikethrough,separator,justifyleft,justifycenter," +
"justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,|,cut ,copy,paste,undo,redo" +
"link,unlink,image,cleanup,code,hr,|,removeformat,formatselect,|,fontselect,fontsizeselect," +
"sub,sup,|,forecolor,backcolor,forecolorpicker,backcolorpicker,charmap,visualaid," +
"anchor,blockquote"
});
}
Ctrl+S in textarea causes IE9 standard save dialog to appear in this case. How to allow Ctrl+S to save form in tinyMCE also ?