Reputation: 1279
I have a jqgrid view and have added the option to insert a new row using jqGrid interface. While adding, i have some server side validation if there is no error then it will be updated otherwise the popup should be available with error message. In case of validation error my pop is available but the input text clears in the insert form. Code Snippet:
$("#tblJQGrid").jqGrid(
{
//grid details
}
).navGrid('#tblJQGrid_toppager',
{
edit: false, add: true, del: false, search: true, refresh: true,
},
{
// edit options
},
{
// add options
url: "insert/something",
closeAfterAdd: true,
reloadAfterSubmit: true,
afterComplete: function (response) {
if (response.responseText) {
if (response.responseText == " updated successfully") {
$(".ui-icon-close").trigger('click');
alert(response.responseText);
}
else {
alert(response.responseText);
}
}
}
},
{
// delete options
},
{ recreateFilter: true, overlay: true, multipleSearch: true, multipleGroup: true }
);
Upvotes: 0
Views: 179
Reputation: 221997
It's important to write in the text of all questions, especially if you report an error, which version of jqGrid and from which fork (free jqGrid, Guriddo jqGrid JS or an old jqGrid in version <=4.7) you use.
The standard way of server validation during form editing means that the server reports the text or HTML fragment with error description in the body of editing response and the status code of the response is an HTTP error (>=400). Only if your server side code unable to set HTTP status code then you should use afterSubmit
(not afterComplete
) callback to analyse the server response and to inform jqGrid whether the response contains an error report or not. The callback afterSubmit
have to return [true]
(an array with true
as the first element) in case of successful editing/adding operation. It should return the array in the form [false, "some string with the error description"]
in case of error. The afterComplete
will be called too late and it can't be used for validation.
Upvotes: 1