PDA

View Full Version : Is CompositeElementLite working as expected



gordon
28 Feb 2007, 7:48 AM
Jack,

I'd like to use your DateField in our forms but I can't find an example of how to do this and I can't work it out from the source.

In the meantime I'm using an old date editor. However using CompositeElementLite.each() doesn't appear to be behaving as I would expect.

Here's my code.


bd = Ext.get('viewport');
bd.select('input.date-picker').each(function(el){
new DateEditor(el);
});


It seems to be having trouble with this.el which is set to document.body in the constructor:

Ext.CompositeElementLite = function(els){
Ext.CompositeElementLite.superclass.constructor.call(this, els);
this.el = new Ext.Element(document.body, true);
};
Ext.extend(Ext.CompositeElementLite, Ext.CompositeElement, {
...
each : function(fn, scope){
var els = this.elements;
var el = this.el;
for(var i = 0, len = els.length; i < len; i++){
el.dom = els[i];
if(fn.call(scope || el, el, this, i) === false){
break;
}
}
return this;
}
});

If we expand the first line of the for loop above we get:

document.body.dom = els[i]
Is this really what you intended?

Thanks,

Gordon

jack.slocum
28 Feb 2007, 8:48 AM
The argument to each is the flyweight element object. So what happens is your DateField gets bound to that flyweight (and the flyweight's dom node is not static).


bd = Ext.get('viewport');
bd.select('input.date-picker').each(function(el){
new DateEditor(el.dom); // <-- use the dom node
});

I'm not sure that code will work though. In the next rev (coming shortly), you can augment existing fields with the Ext field functionality by using a "target" config option (I couldn't think of a good name).


bd = Ext.get('viewport');
bd.select('input.date-picker').each(function(el){
new DateEditor({target: el.dom});
});

gordon
28 Feb 2007, 8:54 AM
Jack, that worked a treat. Thanks.

Gordon