2

Before changed row is saved custom function needs to be called to validate save possibility.

If this custom function returns false, row save should be cancelled and row should remain in edit mode so that error can corrected and saved again.

How to validate row in inline and form editing modes? I havent found any row level validation function. Shoult I add custom validation function to column to validate row or is there better solution ?

Andrus
  • 26,339
  • 60
  • 204
  • 378

1 Answers1

7

If I understand you correct you should use custom validation editrules

editrules: {
    custom:true,
    custom_func: function(value,colname) {
        // return [true,""] in case of successful validation
        // [false,"Your error message"]; in case of validation error
    }
}

See jqGrid documentation for the code example.

jqGrid has only cell level validation, but depend on how you use inline editing (for example only one row is in editing mode an once) you can get the data from the whole editing row. You have many options. For example you can get the row data manually or just define validation rules for all columns which have an interest, inside of validation of the first columns you just save the value in the property of an external object and inside of the last validation function you can access all the saved data to make real row validation.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Validation is used to send unsaved header data to server which needs to be saved before or with with detail save. I tried `editrules = {custom = true, custom_func = function (value, colname) { if (!SaveHeader()) return [false,'']; else return [true,'']; }}`. On error SaveHeader prints error message and returns false. However jqGrid still prints error message even if custom_func returns [false,''] . How to suppress this error message or at least printing the column value in error message? Or is it better/how to send form data together with row data to edit/add method in server ? – Andrus Jul 25 '11 at 14:54
  • 1
    @Andrus: The client side validation is exactly to display the user a message in case of wrong data, so I don't understand why you try to use `[false,'']`. The `SaveHeader` should **not display** any message, but gives you back and the `custom_func` should return the message as the second element of the array. – Oleg Jul 25 '11 at 15:56
  • Thank you. Two issues: 1. jqGrid prints column value in start of message itself.. This value is not related to row validation error, so I'm looking for a way to discard it. 2. jqGrid error message appears in modal dialog. SaveHeader() adds modeless error message into screen, I'm looking for a way for such message. – Andrus Jul 26 '11 at 06:27
  • 1
    @Andrus: What you want you can easy implement in `beforeSubmit` in case of form editing, but you can't implement your requirements in case of inline editing. Inline editing use the line https://github.com/tonytomov/jqGrid/blob/v4.1.2/js/grid.inlinedit.js#L174 to add the name of the column to the message and display the message directly after the statement in https://github.com/tonytomov/jqGrid/blob/v4.1.2/js/grid.inlinedit.js#L188. So you **have to change jqGrid code** to implement your requirements. I don't see another simple workaround possibility. – Oleg Jul 26 '11 at 08:22
  • thank you. I marked your answer and upvoted it. I can live with the fake row value printed from inline editing validation – Andrus Jul 27 '11 at 13:42