PDA

View Full Version : How can I force user only select dates until yesterday?



coooolmagic
17 Nov 2010, 3:56 AM
How can I force user only select dates until yesterday? using date field


Ext.apply(Ext.form.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 = 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;
}
});

Screamy
17 Nov 2010, 5:37 AM
Take a look at Ext.form.DateField.maxValue, it may save you some code.

Thx.

laurentParis
17 Nov 2010, 7:58 AM
I suggest to you :

don't use xxxx.validate() but xxxx.markInvalid(myErrorMsg); or clearInvalid()
problem is when you have two dates with vtype, validate function call vtype, vtype call validate...etc infinite cycle !