PDA

View Full Version : setValue() for datepicker doesn't work



hr.sheik
21 May 2013, 11:32 PM
I tried to set value for a date picker control and i am getting an error message Cannot call method 'setDisabled' of undefined. Also i am not able to see dates, month and year after calling setValue() method.

Below is my code:


Ext.create('Ext.panel.Panel', {
title: 'Choose a future date:',
width: 200,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
xtype: 'datepicker',
handler: function(picker, date) {
// do something with the selected date
},
listeners: {
'afterrender': {
fn: function (self, eOpts) {
self.setValue(new Date());
}
}
}
}]
});

slemmon
23 May 2013, 11:21 AM
Try using boxready instead of afterrender:



Ext.create('Ext.panel.Panel', {
title: 'Choose a future date:',
width: 200,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
xtype: 'datepicker',
handler: function(picker, date) {
// do something with the selected date
},
listeners: {
'boxready': {
fn: function (self, eOpts) {
self.setValue(Ext.Date.add(new Date(), Ext.Date.DAY, 1));
}
}
}
}]
});