Hello everyone!
following this stackoverflow’s solution suggest:
I was trying to make the same when opening form editor but using jqgrid js 5.6.0 and trying to implement a test sample it doesn’t even get inside the custom_func part if a field is empty since those console.log doesn’t fire in chrome:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
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.0+ changed something about custom_func and firing custom alerts?
Thanks in advance to all! Cheers! 🙂
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top