1
votes

using plugin RowEditing on a grid how to display a custom Error Message on the 'validateedit' when i cancel the validation ?

validateedit :  function(editor, e) {

     if (condition) {
    e.cancel = true;
    // how to add an error message to a field 
    }
}
2

2 Answers

8
votes

You can use the built-in model validation, and send the whole Errors collection into form.markInvalid(). This way you don't need to process each field individually.

validateedit: function(editor, e, eOpts){
    var newModel = e.record.copy(); //copy the old model
    newModel.set(e.newValues); //set the values from the editing plugin form

    var errors = newModel.validate(); //validate the new data
    if(!errors.isValid()){
      editor.editor.form.markInvalid(errors); //the double "editor" is correct
      return false; //prevent the editing plugin from closing
    }
}

Reference

Make sure you use return false instead of e.cancel = true. e.cancel = true will cause subsequent edits on the still open row editor to fail as well. You would then have to click the cancel button and re-edit the row to resume editing.

1
votes

Just use the selectors and methods associated with the Form and Field

editor.editor.getForm().findField('fieldName').markInvalid('Message here');