following this stackoverflow's solution suggest:
How to display custom alert boxes in custom_func of jqgrid
I was trying to make the same when opening form editor but using jqgrid js 5.6.0 and doing a sample it doesn't even get inside the custom_func part since those console.log doesn't fire in chrome:
jQuery(document).ready(function($){
var useCustomDialog = false, oldInfoDialog = $.jgrid.info_dialog;
$.extend($.jgrid,{
info_dialog: function (caption, content, c_b, modalopt) {
console.log('checking useCustomDialog: ' + useCustomDialog);
if (useCustomDialog) {
// display custom dialog
console.log('getting custom dialog...');
useCustomDialog = false;
alert(content);
} else {
console.log('getting old dialog...');
return oldInfoDialog.apply (this, arguments);
}
}
});
$("#test").jqGrid({
shrinkToFit: false,
forceFit: true,
datatype: "json",
url: '../myphp.php?op=1',
editurl: '../myphp.php?op=2',
colModel: [
{
label: 'ID',
name: 'ID',
width: 10,
jsonmap: 'ID',
key: true,
editable: false,
editrules : {
required: true,
edithidden: true
},
hidden: true,
editoptions:{
dataInit: function(element) {
$(element).attr("readonly", "readonly");
}
}
},
{
label: 'Field1',
name: 'Field1',
width: 300,
jsonmap: 'Field1',
editable: true,
editrules : {
required: true,
custom: true,
custom_func: function (val, nm, valref) {
console.log('tryig to get Field1 custom dialog here.... ' + val);
if ( isBlank(val) ) {
console.log('Field1 is empty');
useCustomDialog = true; // use custom info_dialog!
return [false, "Field1 is mandatory!"];
}
else {
console.log('Field1 is not empty');
return [true];
}
}
},
editoptions:{size:50}
},
{
label : 'Field2',
name: 'Field2',
width: 300,
jsonmap: 'Field2',
editable: true,
editrules : {
required: true,
custom: true,
custom_func: function (val, nm, valref) {
console.log('tryig to get Field2 custom dialog here.... ' + val);
if ( isBlank(val) ) {
console.log('Field2 is empty');
useCustomDialog = true; // use custom info_dialog!
return [false, "Field2 is mandatory!"];
}
//else {
// console.log('Field2 is not empty');
// return [true];
//}
}
},
editoptions:{size:50}
},
],
ondblClickRow: function(rowid) {
jQuery(this).jqGrid('editGridRow',
rowid,
{
editCaption: "Modify",
recreateForm:true,
dataheight: 500,
height: 600,
width: 680,
top: 40,
left: 170,
closeOnEscape: true,
onclickSubmit : function (options, postdata) {
if( confirm('Save this record (Y/N)?') ) {
console.log( JSON.stringify(postdata) );
return {
returndata : JSON.stringify( postdata )
};
}
},
closeAfterEdit: true,
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
}
}
);
},
sortname: 'Field1',
sortorder : 'asc',
loadonce: true,
viewrecords: true,
height: 200,
rowNum: 10,
caption: "Test table",
pager: "#testPager"
});
function isBlank(str) { return (!!!str || /^\s*$/.test(str)); }
});
maybe I forgot something to consider or even on jqGrid 5.6+ changed something about custom_func and firing custom alerts? Thanks in advance to all! Cheers! :-)