Search code examples
jqgridjqgrid-formatter

Before Submit function not firing in jqgrid


Hi I have a jqgrid edit functionality through format actions. Is it possible can I use the method beforeSubmit and perfrom the validation.

formatoptions: {
                        keys: true, // we want use [Enter] key to save the row and [Esc] to cancel editing.
                        onEdit: function (rowid) {
                            //alert("in onEdit: rowid=" + rowid + "\nWe don't need return anything");
                        },
                        onSuccess: function (jqXHR) {
                            $('input[id*="gs_"]').val("");
                            $grid.setGridParam({ search: false, postData: { "filters": ""} ,datatype: 'json'}).trigger("reloadGrid");
                            // the function will be used as "succesfunc" parameter of editRow function
                            // (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#editrow)
                            /*alert("in onSuccess used only for remote editing:" +
                                "\nresponseText=" + jqXHR.responseText +
                                "\n\nWe can verify the server response and return false in case of" +
                                " error response. return true confirm that the response is successful");
                            // we can verify the server response and interpret it do as an error
                            // in the case we should return false. In the case onError will be called
                            return true;*/
                        },
                        onError: function (rowid, jqXHR, textStatus) {
                            // the function will be used as "errorfunc" parameter of editRow function
                            // (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#editrow)
                            // and saveRow function
                            // (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#saverow)
                            /*alert("in onError used only for remote editing:" +
                                "\nresponseText=" + jqXHR.responseText +
                                "\nstatus=" + jqXHR.status +
                                "\nstatusText" + jqXHR.statusText +
                                "\n\nWe don't need return anything");*/
                        },
                        afterSave: function (rowid) {
                            //alert("in afterSave (Submit): rowid=" + rowid + "\nWe don't need return anything");
                        },
                        afterRestore: function (rowid) {
                            //alert("in afterRestore (Cancel): rowid=" + rowid + "\nWe don't need return anything");
                        },
                        delOptions: myDelOptions
                    }
    }       ],

The function is never getting fired. I wish to perfrom ajax request for validation purpose ,

Kidnly provide help and thanks


Solution

  • There are beforeSaveRow in inline editing (if you don't use some old version of jqGrid). The callback can't be set inside of formatoptions of formatter: "actions", but you can use $.jgrid.inlineEdit instead:

    $.extend(true, $.jgrid.inlineEdit, {
        beforeSaveRow: function (options, rowid) {
            ...
            return true; // return false break submiting
        }
    });