0

I'm having the following problem: I want to validate a DateField so that it has a value between the minValue / maxValue range. (greater or equal, lower or equal)

The problem is that I think the framework takes the time in milliseconds.

I've tried using a custom vtype such as:

Ext.apply(Ext.form.VTypes,{
dates: function(val, field){
    try{
        if(this.disabled){
            return true;
        }

        if(Ext.value(val,null,false)==null){
            this.datesText = "This field is required.";
            return this.allowBlank; //the text message won't be shown in case blank is allowed.
        }

        if(Ext.value(field.minValue,null,false)!=null){
            if(Ext.util.Format.date(val,"Ymd")<Ext.util.Format.date(field.minValue,"Ymd")){
                this.datesText = "The value is invalid.<br/>";
                this.datesText = "it must be greater or equal than " + field.minValue;
                return false;
            }
        }

        if(Ext.value(field.maxValue,null,false)!=null){
            if(Ext.util.Format.date(val,"Ymd")>Ext.util.Format.date(field.maxValue,"Ymd")){
                this.datesText = "The value is invalid.<br/>";
                this.datesText = "It must be lower or equal than " + field.maxValue;
                return false;
            }
        }

        return true;

    }catch(e){
        return false;
    }
},
datesText: 'The value is invalid.', //error message
datesMask: / /  //regexp to filter the characters allowed

});

Basically what it does is convert the values to a 'Ymd' format and then compare values as numbers.

If I debug this code, the validation goes okay, but for some reason I still get an error message. I believe the framework is trying to validate the field again after my validation.

Thank you!

Sebastián

4

2 回答 2

1
minValue : Date/String

允许的最短日期。可以是 Javascript 日期对象或有效格式的字符串日期(默认为 null)。

maxValue : Date/String

允许的最大日期。可以是 Javascript 日期对象或有效格式的字符串日期(默认为 null)。

如果您需要禁用某些日期

disabledDates : Array

要禁用的“日期”数组,作为字符串。这些字符串将用于构建动态正则表达式,因此它们非常强大。一些例子://禁用这些确切的日期:

disabledDates: ["03/08/2003", "09/16/2003"]

// 每年禁用这些日子:

disabledDates: ["03/08", "09/16"]

// 仅匹配开头(如果您使用的是短年份,则很有用):

disabledDates: ["^03/08"]

// 禁用 2006 年 3 月的每一天:

disabledDates: ["03/../2006"]

// 禁用每年三月的每一天:

disabledDates: ["^03"]
于 2010-11-14T00:58:14.517 回答
0

而不是上面提到的固定日期,使用这个:

//doesn't allow past today
maxValue: new Date() 
//Only allows 7 days in the past from current date.
minValue: Ext.Date.add(new Date(), Ext.Date.DAY, -7) 
于 2012-01-16T14:03:11.873 回答