开发者

ExtJS - dirty check on form works only the first time

I am doing a dirty check before submitting a Edit details form. This works the first time after the form is loaded, but if I submit the form once, the dirty check ceases to work on subsequent calls.

if(editForm.getForm().isDirty()) {
    editForm.getForm().submit( {
        url:'app/update',
        waitMsg:'Saving data',
        success:function(form,action) {
              Ext.Msg.alert("Success", "Successfully updated");
        },
        failure: function(form,action) {
              Ext.Msg.alert("Failure", "Faile开发者_JS百科d to update");
        }
    });
} else {
    Ext.Msg.alert("Message", "Nothing has been changed since you last saved.");
}


This is because your form is comparing the field values with initial field values.

You can use the reset() method to reset the form after submit. If you need to provide users to continue edit on the same form, you can reload the form with latest data using loadRecord() method. Or you will have to make use of the trackResetOnLoad property. Set this property to true.


This worked for me. I added this after a successful form submit.

form.getForm().getFields().each(function(field){
   field.resetOriginalValue( );
});


Have you looked at the Ext.form.Panel property trackResetOnLoad ? Try setting it to true by stating editForm.trackResetOnLoad = true; this might help. Good luck!


I know this is an old post but I thought I'd share another solution.

The isDirty() method checks against the original values. Upon saving the values (in your success call back function) you could have this code which sets the originalValues to your new successfully saved values:

var fields = editForm.getForm.getFields().items;
Ext.each(fields, function(field){
    field.originalValue = field.getValue();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜