Extjs4.x Vtype扩展实现开始日期小于结束日期

1.扩展Vtype

    开始日期必须小于结束日期,结束日期必须大于开始日期,不能选的日期处于禁用状态

//实现验证开始时间必须小于结束时间
Ext.apply(Ext.form.VTypes, {
            daterange : function(val, field) {
                var date = field.parseDate(val);
                if (!date) {
                    return;
                }
                if (field.startDateField
                        && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax
                                .getTime()))) {
                    var start = Ext.getCmp(field.startDateField);
                    start.setMaxValue(date);
                    start.validate();
                    this.dateRangeMax = date;
                } else if (field.endDateField
                        && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin
                                .getTime()))) {
                    var end = Ext.getCmp(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;
            }
        });


2.用法


'统计区间:',{
              id:'timeId',
              xtype:'datefield',
              editable:false,
              format:"Y-m-d",
              width : 160,
              vtype : 'daterange',//daterange类型为上代码定义的类型
              endDateField : 'overtimeId'//必须跟endDate的id名相同

          },'一',{
              id:'overtimeId',
              xtype:'datefield',
              editable:false,
              format:"Y-m-d",
              width : 160,
              vtype : 'daterange',//daterange类型为上代码定义的类型
              startDateField : 'timeId'//必须跟startDate的id名相同

          }

出处:http://www.cnblogs.com/zhougaojun/p/3320709.html



你可能感兴趣的:(ExtJs)