PDA

View Full Version : how to get value in datefield?



big
15 Feb 2010, 9:38 AM
how to get value in datefield?


var simpleForm = new Ext.FormPanel ({
labelWidth: 75,
method: 'POST',//////////////////
renderTo: "simple-form",
frame: true,
title: 'Search',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults: {width: 230},
items: [{
fieldLabel: 'Station',
name: 'station',
id: 'station',
xtype: 'textfield',
allowBlank:false

},{


fieldLabel: 'Date from',
name: 'datefrom',
id: 'datefrom',
xtype:'datefield',
format:'d/m/Y'
}],
buttons: [{
text: 'Search',
handler: function () {

store.reload({
params: {
station: Ext.getCmp("station").getValue(),

datefrom: Ext.getCmp("datefrom").getValue()
}
});


}
},{
text: 'Cancel',
handler: function () {
simpleForm.getForm().reset();
}
}]
});

ShatyUT
15 Feb 2010, 9:44 AM
The getValue() method is correct. Are you getting any errors from FireBug?

big
15 Feb 2010, 9:48 AM
it not show date on grid when i search date with simpleform.
and in firebug ,my database not sent value which i want.(it's blank.)
i want to compare value with php but another value is show.(date value in format d/m/Y not show)

ShatyUT
15 Feb 2010, 10:12 AM
I'm no expert with this library but I would suggest grabbing the datefield component and setting a break point so that you can inspect the elements of your datefield and see which property contains that date if any.



handler: function () {
var df = Ext.getCmp("datefrom");
var val = df.getValue(); // <--- Set break point here and check properties of df
store.reload({
params: {
station: Ext.getCmp("station").getValue(),
datefrom: Ext.getCmp("datefrom").getValue()
}
});
}


Are you setting a value on the datefield or just trying to grab the default value?

I put the following on a form and after I set a value on the field (and changed focus) the alert shows the value.



{
xtype: 'datefield',
id: 'df',
listeners: {
change: function(df, newValue, oldValue) {
Ext.Msg.alert('date', Ext.getCmp('df').getValue());
}
}
}


Now, the value returned will be something like this:

Tue Feb 16 2010 00:00:00 GMT-0600 (Central Standard Time)

which may not be what you want. If you use the getRawValue() method instead you'll get something like this:

02/16/2010

bclinton
15 Feb 2010, 11:04 AM
it not show date on grid when i search date with simpleform.
and in firebug ,my database not sent value which i want.(it's blank.)
i want to compare value with php but another value is show.(date value in format d/m/Y not show)

Can you show the code you are using to populate the form with values?

Eugen_
15 Feb 2010, 11:14 AM
it not show date on grid when i search date with simpleform.
and in firebug ,my database not sent value which i want.(it's blank.)
i want to compare value with php but another value is show.(date value in format d/m/Y not show)
Maybe this thread (http://www.extjs.com/forum/showthread.php?p=435863) will help you.

gaellafond
23 Mar 2011, 12:11 AM
The method getValue() return a date object. You can format it as you want. This is very useful when you want the date to be display in a certain format in the form, but store in a different format.

var dateStr = datefield.getValue().format('Y-m-d').trim();

The trim can probably be omit, I got this line from:
http://ww.extjs.com/learn/Ext_FAQ_Forms