1

在网格上使用插件 RowEditing 如何在取消验证时在“validateedit”上显示自定义错误消息?

validateedit :  function(editor, e) {

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

2 回答 2

8

您可以使用内置的模型验证,并将整个 Errors 集合发送到form.markInvalid(). 这样您就不需要单独处理每个字段。

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
    }
}

参考

确保使用return false而不是e.cancel = true. e.cancel = true将导致在仍然打开的行编辑器上的后续编辑也失败。然后,您必须单击取消按钮并重新编辑该行才能继续编辑。

于 2013-04-15T13:46:43.573 回答
1

只需使用与表单和字段关联的选择器和方法

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

于 2012-11-15T23:45:10.047 回答