This is some Ext 3 code I played with earlier today for another reason, it may help you:
Code:
Ext.override(Ext.form.TextField,{
isBlank : function(){
var value = this.getRawValue();
return (value.length < 1 || value === this.emptyText);
}
});
// Add the additional 'advanced' VTypes
Ext.apply(Ext.form.VTypes, {
daterange : function(val, field) {
var dependency = Ext.getCmp(field.dependency),
date = field.parseDate(val);
if(!date){
dependency.setMaxValue();
dependency.setMinValue();
return;
}
dependency.allowBlank = false;
if (!field.dateRange || (date.getTime() != field.dateRange.getTime())) {
if (field.dependency.indexOf('start') >= 0){
dependency.setMaxValue(date);
} else if (field.dependency.indexOf('end') >= 0){
dependency.setMinValue(date);
}
field.dateRange = date;
dependency.validate();
}
/*
* 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;
},
password : function(val, field) {
if (field.initialPassField) {
var pwd = Ext.getCmp(field.initialPassField);
return (val == pwd.getValue());
}
return true;
},
passwordText : 'Passwords do not match'
});
Ext.onReady(function(){
Ext.QuickTips.init();
// turn on validation errors beside the field globally
Ext.form.Field.prototype.msgTarget = 'side';
var bd = Ext.getBody();
/*
* ================ Date Range =======================
*/
var syncBlank = function (field){
var dep = Ext.getCmp(field.dependency);
if (field.isBlank() && dep.isBlank()){
dep.allowBlank = true;
field.allowBlank = true;
dep.validate();
field.validate();
}
};
var dr = new Ext.FormPanel({
labelWidth: 125,
frame: true,
title: 'Date Range',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults: {width: 175},
defaultType: 'datefield',
items: [{
fieldLabel: 'Start Date',
name: 'startdt',
id: 'startdt',
vtype: 'daterange',
listeners: {
blur: syncBlank
},
dependency: 'enddt' // id of the end date field (must have 'end' in it)
},{
fieldLabel: 'End Date',
name: 'enddt',
id: 'enddt',
vtype: 'daterange',
listeners: {
blur: syncBlank
},
dependency: 'startdt' // id of the start date field (must have 'start' in it)
}]
});
dr.render('dr');