PDA

View Full Version : BasicForm isDirty() works unexpected when using combo.setValue(XXX) after AJAX call



toolware
25 Oct 2010, 6:56 AM
I have a form with a bunch of fields and a combo box.

When I initialize the form, I use setValue(xxx) in quite a few places. When I check formPanel.getForm().isDirty() - it works as expected (in a scenario where I submit the form).

I added another element to my form (combo), that triggers an AJAX call, which, when it returns, does combo.setValue(xxx).

It seems that this action marks my form as dirty, since after this, isDirty() always returns true.

Please advise - I thought using setValue() sets a new "clean" state var for the field?

Thanks!

P.S.
I saw in this thread:
http://www.sencha.com/forum/showthre...asicForm.load()
...that setting
trackResetOnLoad: true
...would fix this issue.

However, my form is still marked dirty when my ajax method returns and does setValue() on the combo.

Condor
25 Oct 2010, 7:43 AM
trackResetOnLoad only affects setValues, not a single setValue.

You can reset the dirty flag by using:

combo.originalValue = combo.getValue();

toolware
25 Oct 2010, 8:59 AM
Yay that did it!

I didn't realize "Public Properties" like this one were meant to be interacted with, after the component is initialized. I'm assuming this is an isolated occurrence, where this works.

Thank you!

Condor
25 Oct 2010, 10:27 AM
Good conclusion. Properties should be considered read-only and you should only modify them if you've looked at the code to see if it would actually work.