在网格上使用插件RowEditing如何在取消验证时在'validateedit'上显示自定义错误消息?
validateedit : function(editor, e) {
if (condition) {
e.cancel = true;
// how to add an error message to a field
}
}
Run Code Online (Sandbox Code Playgroud)
小智 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
}
}
Run Code Online (Sandbox Code Playgroud)
确保使用return false而不是e.cancel = true.
e.cancel = true将导致仍然打开的行编辑器上的后续编辑失败.然后,您必须单击取消按钮并重新编辑该行以继续编辑.
| 归档时间: |
|
| 查看次数: |
5962 次 |
| 最近记录: |