Hybrid View
-
8 May 2007 2:01 PM #1
isDirty works fine on empty form but returns true after form.load
isDirty works fine on empty form but returns true after form.load
Hello,
I just built ext from the SVN and was testing the monitoring and isDirty.
I wanted to accomplish a 'Save' button when the data in a form isValid && isDirty.
So I tuned on monitoring of the form and check for the event like this.
This works perfectly with an empty form. I have to make some change and also have valid data in the fields. After that my button is enabled.HTML Code:form[tmpdlgid].on('clientvalidation', function(){ if(form[tmpdlgid].isDirty() && form[tmpdlgid].isValid()){ console.debug (form[tmpdlgid].isDirty()); submitbutton[tmpdlgid].enable(); } });
However, when on the same form, using form load...
...isDirty is always true. Note that I also tried stopMonitoring before load and startMonitoring after.HTML Code:console.debug('got an ID, loading...'); form[dlgid].stopMonitoring(); form[dlgid].load({ url : 'jsonform.php', waitMsg : 'loading data...', params : {'id' : id} }); form[dlgid].startMonitoring();
Looks like a bug?
[EDIT]
Either this is by design or a bug..
I put:into ext at the isDirty function.HTML Code:console.debug('isDirty -> new value: '+String(this.getValue())+' / old value: '+String(this.originalValue));
This is what I got in Firebug:
isDirty -> new value: jim / old value:
Means that the isDirty function is checking this.originalvalue which is empty while it should have the loaded data which in this case is 'jim'. Is this by design? Shoudn't dirty mean any change since the original loaded data?
-
9 May 2007 8:53 AM #2
The config option "trackResetOnLoad" will reset originalValues when forms are loaded if set to true.
-
9 May 2007 9:40 AM #3
Thanks Jack!!!
I looked into the source code and saw how you did it. Now I understand.
Thanks for your reply!!
Frank
-
9 May 2007 10:48 PM #4
does this mean trackResetOnLoad and the isDirty() support are both tied to the originalValue used for .reset()
or: when i load a record with trackResetOnLoad=false the isDirty() will only check the current value against the inital empty state?
if so, i guess some shortcut to explicitly clear a form or a field would be useful.
-
10 May 2007 1:27 PM #5
Yes, originalValue is the original value.

-
18 Sep 2007 10:21 AM #6
-
29 Sep 2007 3:41 PM #7
.. Edit ..
I think there needs to be a way to reset a form's isDirty property to false and reset each fields originalValue to the current values. Here's why:
1. Form loads (all fields are clear, adding new record)
2. User fills in the fields and submits the form
3. Form submit was successful, now hide/show certain buttons to "maintain" that record. I.e. Remove the "Insert Record" button and show the "Update Record" button.
At this point any call to reset() should reset to the last successful saved state without having to reload the record after the successful save callback. Something like "form.resetIsDirty()" which would reset the dirty state of each field and redefine each fields originalValue to the current value. This would be very helpful.
I also agree with neongrau that there should be some method to explicitly clear all fields regardless of their originalValue.
-
30 Nov 2007 4:34 PM #8
check event fires before originalValue = getValue()
check event fires before originalValue = getValue()
This thread has been helpful for my understanding of how trackResetOnLoad works. I am, however, seeing some strange behavior with checkboxes on my form.
My form consists of checkboxes and textboxes. I have the checkbox check event wired up to the same handler as the textbox blur event:
If I set a breakpoint on the first line, I notice that as the form is loading the checkboxes whose value changes during load return isDirty() = true. This is not the case for the textboxes. Interestingly, if I instead handle the blur event on the checkboxes isDirty() = false.PHP Code:function onFormValueChanged(source){
if (source.isDirty()) {
// do stuff...
}
}
I might be satisfied with just using the blur event for all the form controls, but I need to invoke onFormValueChanged when the user merely checks the checkbox and doesn't leave focus.
I did set a breakpoint on ext-all-debug.js, line 27324. For the checkboxes, originalValue does get set to getValue() when I have trackResetOnLoad = true; but the problem is that this assignment happens *after* the check event fires during form load. With the blur event the assignment happens before the event fires.
Is this by design? If so, what's a good work-around? It seems to me that trackResetOnLoad may not be working properly with checkboxes, but I'm still largely an ExtJS noob, so perhaps I'm missing something here.
-
30 Nov 2007 5:09 PM #9
I figured out an OK work-around: wire up the check event handlers in a BasicForm.actioncomplete event handler. This solves the problem for now, but it seems like I shouldn't have to do this.
-
14 Oct 2010 4:25 AM #10


Reply With Quote