如何使用 min/maxValue 验证 Ext.form.DateField,而不使用时间?
我遇到以下问题:我想验证 DateField 以便它的值介于 minValue / maxValue 范围之间。 (大于或等于,小于或等于)
问题是我认为框架花费的时间以毫秒为单位。
我尝试过使用自定义 vtype,例如:
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
});
基本上,它的作用是将值转换为“Ymd”格式,然后将值作为数字进行比较。
如果我调试此代码,验证会正常进行,但由于某种原因我仍然收到错误消息。我相信框架正在尝试在我验证后再次验证该字段。
谢谢你!
塞巴斯蒂安
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
允许的最短日期。可以是 Javascript 日期对象或有效格式的字符串日期(默认为 null)。
允许的最大日期。可以是 Javascript 日期对象或有效格式的字符串日期(默认为 null)。
如果您需要禁用某些日期,
则要禁用的“日期”数组(作为字符串)。这些字符串将用于构建动态正则表达式,因此它们非常强大。一些例子:
// 禁用这些确切日期:
// 禁用每年的这些天:
// 只匹配开头(如果您使用短年份则有用):
// 禁用 2006 年 3 月的每一天:
// 禁用每年 3 月的每一天:
The minimum allowed date. Can be either a Javascript date object or a string date in a valid format (defaults to null).
The maximum allowed date. Can be either a Javascript date object or a string date in a valid format (defaults to null).
and in case you needed to disable some dates
An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular expression so they are very powerful. Some examples:
// disable these exact dates:
// disable these days for every year:
// only match the beginning (useful if you are using short years):
// disable every day in March 2006:
// disable every day in every March:
使用以下命令代替上面提到的固定日期:
Instead of fixed dates mentioned above, use this: