View Full Version : setvalue not working for compositefield

1 Aug 2010, 4:56 AM
I'm trying to set field value using code Ext.getCmp('event_start_date').setValue("2010-07-28"); withing compositefield but i'm getting js error Ext.getCmp('event_start_date') not an object

xtype: 'compositefield',
fieldLabel: 'Date Range',
msgTarget : 'side',
anchor : '-20',

items: [
xtype: 'datefield',
fieldLabel: 'Event Start Date',
id: 'event_start_date',
name: 'event_start_date',
anchor: '100%',
format: 'Y-m-d',
allowBlank: false
xtype: 'timefield',
fieldLabel: 'Event Start Time',
id: 'event_start_time',
anchor: '100%',
format:'h:i A',
minValue: '08:00 AM',
maxValue: '10:00 PM',
allowBlank: false

When i remove compositefield then same code work for setValue works Ext.getCmp('event_start_date').setValue("2010-07-28");

Any clue?

1 Aug 2010, 4:16 PM
Both component have the same id, try changing the second one's id.

1 Aug 2010, 8:36 PM
Both component have the same id, try changing the second one's id.

First one is event_start_date and second is event_start_time.

1 Aug 2010, 9:46 PM
This should work. Are you trying to set the value before the field is created?

1 Aug 2010, 9:59 PM
No, I've defined the fields then after that I'm setting values in them. If i take fields out of composite field then it's work fine else it give error Ext.getCmp('event_start_date') not an object

1 Aug 2010, 10:14 PM
Sorry, my bad. Only instance in which Ext.getCmp has not worked for me was when I was using frames, other than that I have no clue.

2 Aug 2010, 1:26 AM
Ext doesn't work very well with frames (it assumes there is one single document).

If you want to query components in different frames, then I recommend using the ManagedIframe user extension.

2 Aug 2010, 2:24 AM
i'm not sure what do you mean by frames. I've all js in one single file. I'm creating window and in that i've form panel and under that i've that composite fields. I'm wondering why only under composite field that field is unreachable.

2 Aug 2010, 2:58 AM
CompositeField does have it's limitations (find, findBy, cascade, findField etc. don't work), but Ext.getCmp() should still work.

Are you absolutely, 100% sure the component has been created when you try to set the value?

If you want to be sure, replace the {xtype:'datefield',...} with a new Ext.form.DateField({...})

2 Aug 2010, 4:09 AM
I tracked the error. Unfortunately i had defined variables with same name which was causing conflict. Ext.getCmp() is now working.

2 Aug 2010, 4:41 AM
and also ref's wont work...

2 Aug 2010, 6:12 AM
... and defaultType and defaults won't work, too