2012-11-14 44 views
2

使用插件在網格上的RowEditing當我取消驗證時如何在'validateedit'上顯示自定義錯誤消息?Extjs 4 rowediting自定義驗證

validateedit : function(editor, e) { 

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

回答

1

只要使用與表單關聯的選擇和方法,現場

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

8

您可以使用內置的模型驗證,併發送整個錯誤集合到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 
    } 
} 

Reference

確保你使用return false而不是e.cancel = truee.cancel = true將導致仍然打開的行編輯器上的後續編輯也失敗。 然後您必須單擊取消按鈕並重新編輯該行以恢復編輯。