在网格上使用插件 RowEditing 如何在取消验证时在“validateedit”上显示自定义错误消息?
validateedit : function(editor, e) {
if (condition) {
e.cancel = true;
// how to add an error message to a field
}
}
您可以使用内置的模型验证,并将整个 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
将导致在仍然打开的行编辑器上的后续编辑也失败。然后,您必须单击取消按钮并重新编辑该行才能继续编辑。
只需使用与表单和字段关联的选择器和方法
editor.editor.getForm().findField('fieldName').markInvalid('Message here');