简体   繁体   English

EXTJS日期字段验证

[英]EXTJS date field validation

In the EXTJS, I have a DateField. 在EXTJS中,我有一个DateField。 User entered 'abcd' to that field, if I getValue, it will return an empty string, not the 'abcd'. 用户在该字段中输入了“ abcd”,如果我使用了getValue,它将返回一个空字符串,而不是“ abcd”。

how can I force user to enter correct value for a dateField ? 如何强制用户为dateField输入正确的值? or how can I get the real input in that filed ? 或如何获得该字段中的实际输入?

Thanks. 谢谢。

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. 日期字段还具有与getValue不同的getRawValue方法,因为它不应用getValue所做的任何验证。

To force a user to enter a correct value, you can use the reMask property. 要强制用户输入正确的值,可以使用reMask属性。 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. reMask遮罩可过滤键盘输入。 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/YH:i:s'); 例如,当您在dateField中使用getValue方法时,返回值为: Wed Jul 25 2012 00:00:00 GMT-0300 (BRT) ,但是您可以使用Ext.util.Format.date(date, 'd/m/YH:i:s'); and the return will be "25/07/2012 00:00:00" . 并且返回"25/07/2012 00:00:00"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM