In the EXTJS, I have a DateField. User entered 'abcd' to that field, if I getValue, it will return an empty string, not the 'abcd'.
how can I force user to enter correct value for a dateField ? or how can I get the real input in that filed ?
Thanks.
In the EXTJS, I have a DateField. User entered 'abcd' to that field, if I getValue, it will return an empty string, not the 'abcd'.
how can I force user to enter correct value for a dateField ? or how can I get the real input in that filed ?
Thanks.
Share edited Feb 19, 2013 at 16:02 blong 2,7038 gold badges47 silver badges114 bronze badges asked Jul 30, 2012 at 8:11 user595234user595234 6,26927 gold badges81 silver badges103 bronze badges 2- Posting some code would be helpful. ExtJs DateField does have some validation built-in. – sha Commented Jul 30, 2012 at 10:27
- Related: stackoverflow./q/5693512/320399 – blong Commented Feb 19, 2013 at 16:03
2 Answers
Reset to default 3The datefield has also has a getRawValue method which is different from getValue because it does not apply any of the validation that getValue does.
To force a user to enter a correct value, you can use the reMask property. The default validation logic will allow invalid entry and will show that the entry is invalid with the red highlighting and such. The reMask masks filters keyboard input. In this example it restricts to numbers and forward slash and could be extended to any date format needed.
Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
width: 300,
bodyPadding: 10,
title: 'Dates',
items: [{
xtype: 'datefield',
anchor: '100%',
fieldLabel: 'From',
emptyText: 'mm/dd/yyyy',
maskRe: /[0-9\/]/,
name: 'from_date',
maxValue: new Date() // limited to the current date or prior
}, {
xtype: 'datefield',
anchor: '100%',
emptyText: 'mm/dd/yyyy',
maskRe: /[0-9\/]/,
fieldLabel: 'To',
name: 'to_date',
value: new Date() // defaults to today
}]
});?
When you use getValue
method in a dateField the return will be: Wed Jul 25 2012 00:00:00 GMT-0300 (BRT)
, for example, but you can format the date using, Ext.util.Format.date(date, 'd/m/Y H:i:s');
and the return will be "25/07/2012 00:00:00"
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744818802a4595490.html
评论列表(0条)