javascript - EXTJS date field validation - Stack Overflow

In the EXTJS, I have a DateField. User entered 'abcd' to that field, if I getValue, it will r

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
Add a ment  | 

2 Answers 2

Reset to default 3

The 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

相关推荐

  • javascript - EXTJS date field validation - Stack Overflow

    In the EXTJS, I have a DateField. User entered 'abcd' to that field, if I getValue, it will r

    2天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信