yinjianwei1987
yinjianwei1987
2011-10-27 10:05

ExtJs4 日期范围验证

  • ext
  • javascript

日期验证代码(参照的ExtJs4 的例子:ext-4.0.1-gpl/ext-4.0.1/examples/form/adv-vtypes.html):

Ext.apply(Ext.form.field.VTypes, {
                    daterange: function(val, field) {
                        var date = field.parseDate(val);

                        if (!date) {
                            return false;
                        }
                        if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
                            var start = field.up('form').down('#' + field.startDateField);
                            start.setMaxValue(date);
                            start.validate();
                            this.dateRangeMax = date;
                        }else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
                            var end = field.up('form').down('#' + field.endDateField);
                            end.setMinValue(date);
                            end.validate();
                            this.dateRangeMin = date;
                        }
                        /*
                         * Always return true since we're only using this vtype to set the
                         * min/max allowed values (these are tested for after the vtype test)
                         */
                        return true;
                    },

                    daterangeText: 'Start date must be less than end date'
                 });

 

在日期中使用上面的验证:

{
                                xtype: 'container',
                                fieldLabel: 'Name',
                                hideLabel:false,
                                layout: 'hbox',
                                combineErrors: true,
                                defaults: {
                                    hideLabel: 'true'
                                },
                                items: [{
                                    fieldLabel: '关系建立开始',
                                    hideLabel:false,
                                    editable:false,
                                    name: 'searchMarginBeginStart',
                                    id: 'searchMarginBeginStart',
                                    vtype: 'daterange',   //
                                    xtype: 'datefield',
                                    format:'Y-m-d',
                                    width: 300,
                                    endDateField: 'searchMarginBeginEnd', //
                                    listeners:{
                                        specialkey:function(field,e){
                                            var keyCode = e.getKey();
                                            if(keyCode == e.BACKSPACE){
                                                if(!this.editable){
                                                    e.stopEvent();
                                                    return false;
                                                }
                                            }
                                            
                                        }
                                    }
                                }, 
                                {
                                    fieldLabel: '关系建立结束',
                                    hideLabel:false,
                                    editable:false,
                                    name: 'searchMarginBeginEnd',
                                    id: 'searchMarginBeginEnd',
                                    vtype: 'daterange', //
                                    xtype: 'datefield',
                                    format:'Y-m-d',
                                    width: 300,
                                    startDateField: 'searchMarginBeginStart', //
                                    listeners:{
                                        specialkey:function(field,e){
                                            var keyCode = e.getKey();
                                            if(keyCode == e.BACKSPACE){
                                                if(!this.editable){
                                                    e.stopEvent();
                                                    return false;
                                                }
                                            }
                                            
                                        }
                                    }
                                }]
                            }

 

选好时间后,点击查询,ie提示

这个ie溢出是为什么?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐