首先定义vtype.
使用方法:
Ext.apply(Ext.form.VTypes, {
daterange : function(val, field) {
var date = field.parseDate(val), otherFieldProp, dateProp, other;
if (field.startDateField) {
otherFieldProp = 'startDateField';
dateProp = 'max';
} else if (field.endDateField) {
otherFieldProp = 'endDateField';
dateProp = 'min';
}
if (otherFieldProp && field[otherFieldProp]) {
other = field[otherFieldProp];
if (typeof other == 'string') {
other = field[otherFieldProp] = field.ownerCt
.getComponent(other)
|| Ext.getCmp(other);
}
if (!other[dateProp + 'OldValue']
|| other[dateProp + 'OldValue'] != (date ? date.getTime()
: undefined)) {
other[dateProp + 'Value'] = date;
if (other.menu && other.menu.picker) {
other.menu.picker[dateProp + 'Date'] = date;
other.menu.picker
.update(other.menu.picker.activeDate, true);
}
other[dateProp + 'OldValue'] = date ? date.getTime()
: undefined;
}
}
return true;
}
});
使用方法:
{
fieldLabel : '起始日期',
name : 'QSRQ',
id : 'QSRQ',
vtype : 'daterange',
xtype : 'datefield',
format : 'Y-n-j',
value : rq1,
endDateField : 'JZRQ'
}
{
fieldLabel : '截止日期',
name : 'JZRQ',
id : 'JZRQ',
vtype : 'daterange',
xtype : 'datefield',
value : new Date(),
format : 'Y-n-j',
startDateField : 'QSRQ'
}