PDA

View Full Version : CompositeField override to enable its container behavior



j-joey
27 Dec 2010, 4:54 PM
you have a form and lots of fields, some of them are composite. and you're trying to find fields by using findByType, findBy or other methods of formpanel which are derived from container and result is just heart-breaking. because of composite field is not actually a container, it'll not respond to containers "cascade" method, which is essence of finding inner items, it'll not find inner components. so i just scratched this override;



Ext.override( Ext.form.CompositeField, {
cascade : function( fn, scope, args ) {
if ( fn.apply( scope || this, args || [ this ] ) !== false ) {
if ( this.items && this.items.items ) {
var cs = this.items.items;
for ( var i = 0, len = cs.length; i < len; i++ ) {
if ( cs[ i ].cascade ) {
cs[ i ].cascade( fn, scope, args );
} else {
fn.apply( scope || cs[ i ], args || [ cs[i ] ] );
}
}
}
}
return this;
}
} );

Condor
28 Dec 2010, 12:45 AM
There are some more methods that need to be overridden (see here (http://www.sencha.com/forum/showthread.php?99021-compositefield-gt-getFieldValues-amp-getValue()-are-ignored&p=534961#post534961) - I don't claim that patch is correct though).

j-joey
29 Dec 2010, 2:12 AM
thanks condor, those methods should be overridden too.

also in my case, i need to make this change to cascade method for composite field


...
if ( this.items ) {
...
to

...
if ( this.items && this.items.items ) {
...