PDA

View Full Version : [2.2] run function for all field's form over panel, column, fieldset...


denkoo
10-19-2008, 02:11 AM
When you would running function over all field's form, you can use


myForm.items.each(myFunction(oField) {....});


but if you use column or fieldset or tabpannel... you must use another function that I don't find on extjs... (may be this function exist but I don't know, so I made it and sharing)


Ext.namespace("Ext.ux");
Ext.ux.eachDeep = function (oObj,fFn) {
if(oObj['items'] !== undefined
&& oObj['items']['each'] !== undefined
&& Ext.type(oObj['items']['each']) == 'function') {
oObj['items']['each'](function (oOb) {
Ext.ux.eachDeep(oOb, fFn);
});
}
if(oObj.isFormField) {
return fFn.call(oObj);
}
return false;
};


If you need to call this function,


/* call this function after ajax saving => isDirty return false */
Ext.ux.eachDeep(Ext.getCmp('myFom'), function () {
this.originalValue = this.getValue();
});

Animal
10-19-2008, 08:17 AM
Could you be wanting http://extjs.com/deploy/dev/docs/?class=Ext.Container&member=cascade ?

Animal
10-19-2008, 08:19 AM
And anyway, the BasicForm underpinning the FormPanel does include all the Fields at all depths in its collection*, so you can iterate over that easily.

* A bug has been fixed where dynamically added Fields added to subcomponents are not added to the BasicForm's collection, and this has been fixed in the 3.0 code branch.

denkoo
10-19-2008, 03:24 PM
Great, it's better


myForm.getForm().items.each(myFunction(oField) {....});


Great

Thanks animal for take time for your answer :)

denkoo
10-20-2008, 01:02 AM
Sorry, but I take an extract of my code and I put it online for share my test

http://213.251.166.160/~extjs/examples/deepForm/deepForm.html

Here, I have a form width many imbrications... column, panel, groupcheckbox... I make some test width

Line 237 (deepForm.js)

var f = Ext.getCmp("formID");
f.getForm().items.each(function (oField) {
oField.originalValue = oField.getValue();
});
//f.getForm().isDirty() => alway true If I change groupCheckBox


Line 255 (deepForm.js)
Width recursive function eachDeep

var f = Ext.getCmp("formID");
Ext.ux.eachDeep(f, function () {
this.originalValue = this.getValue();
});
//f.getForm().isDirty() => alway false ! GREAT.... :)


May be it's a specific problem with my code, or may be a bug width groupcheckbox appears on extjs 2.2 !

catmd2b
12-08-2008, 05:14 PM
Animal,

Does this bug fix coincide with this (http://extjs.com/forum/showthread.php?t=41093) post?

Animal
12-10-2008, 08:41 AM
The fix implemented by Jack in the 3.0 branch is an improved and generalized version of that.

The add and remove events now bubble up the ownerCt axis, so that when the FormPanel listens for add events on itself, it in fact receives add events fired by any of its descendants.

In this way, it can find out what was added to it at any level, and collect any fields to add to its MixedCollection.