ExtJS'datefield'验证覆盖 [英] ExtJS 'datefield' validation override

查看:117
本文介绍了ExtJS'datefield'验证覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个具有某种自定义行为的日期列表,特别是我需要能够在同一个字段中输入一个日期或年龄(年龄和作为日期保留的日期) p>

例如输入23将在该字段中留下23作为有效值,或输入22/1/88将22/1/88作为有效值。



所以我试着用一个这样编辑的编辑日期列表(注意有效的覆盖):

 编辑器:{
xtype:'datefield',
格式:'d / m / Y',
validate:function(){
if(!this.value.match (SOME_REGEX){
if(!this.value.match(SOME_REGEX){
return false;
}
}
return true;
}
}

Chrome调试器显示验证事件和验证功能正确的日期,但当我尝试放入一个年龄(int),在进入该字段后,获取该值并尝试从中创建一个日期,将该猜测日期返回到该字段中,



我可以找到的唯一记录的before-validate事件是

  stripCharsRe 

默认为NULL。



任何人都可以看清这个吗?

解决方案

在这种情况下,我会建议您可以使用/配置 TextField 作为编辑器组件并写一个自定义验证器(就像你的代码片段)来验证这些值。



(我知道这不直接回答你的问题,但是你目前的方法是由于DateField构建为处理Date对象的事实,因此遇到问题)



编辑 -



如果日期选择器是必须的,请使用 TriggerField 作为基础组件和onTriggerclick,显示 DatePicker 。 (您将必须设置一个处理函数,当用户使用此选择器选择日期时将被调用。请参阅DatePicker.handler配置选项)


I needed a datecolumn with some custom behaviour, specifically I needed to be able to enter in a date or and age in the same field (with an age staying rendered as an age and a date staying rendered as a date)

Eg. Entering "23" will leave "23" in the field as a valid value, or entering "22/1/88" will leave "22/1/88" as valid value.

So I tried having a datecolumn with the editor defined like this (note the validate override):

editor: {
    xtype: 'datefield',                                 
    format: 'd/m/Y',                                
    validate: function(){
      if(!this.value.match(SOME_REGEX){         
        if(!this.value.match(SOME_REGEX){
          return false;
        }           
      }             
      return true;
    }                               
}

Chrome debugger shows that the validate event and validation function correctly for dates however, when I try and put in an age (int), after hitting enter the field takes the value and tries to make a date out of it, rendering that guessed date back into the field and THEN validate is called.

The only documented before-validate event that I can find is

stripCharsRe

that defaults to NULL.

Can anyone shed any light on this?

解决方案

In this case, I would suggest you use/configure a TextField as the editor component and write a custom validator (just like in your snippet) to validate the values.

(I know this does not answer your question directly but your current approach is going to be riddled with issues due to the fact that DateField is built to handle Date objects)

EDIT -

If Date Picker is a must, use TriggerField as your base component and on its onTriggerclick, display a DatePicker. (You will have to set a handler function that will be called when user selects a date using this picker. See DatePicker.handler config option)

这篇关于ExtJS'datefield'验证覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆