I know I previously asked a similar question enter link description here. This is however, slightly different. ExtJs 2.1 is still converting certain invalid dates like 01/00/2012
to 01/01/2012
I was able to create the code below to prevent this from happening, however this creates a 'script error'. Can anyone help me with a solution that does not generate a script error? Here is the code to create the field:
var d = new Ext.form.DateField({
el: el.dom,
id: id,
format: 'm/d/Y',
hideTrigger: false,
allowBlank: true,
disabled: isDisabled,
validator: extraDateValidator,
altFormats: 'm/d/Y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|mdy|mdY|d|Y-m-d',
validateOnBlur: true,
//validationEvent: false, //string or boolean
invalidText: 'Enter date as MM/DD/YYYY',
menuListeners: Ext.applyIf({
select: function (m, d) {
Ext.form.DateField.prototype.menuListeners.select.apply(this, arguments);
this.focus.defer(100, this);
onDateSelect(m, d, this);
}
})
});
And here is my validator:
function extraDateValidator(date) {
var dateArray = date.split("/");
if (tempForParseDate) {
Date.parseDate = tempForParseDate
}
if (dateArray.length == 3 && (dateArray[0] > 12 || dateArray[0]<1 || dateArray[1]<1) ) {
tempForParseDate = Date.parseDate
Date.parseDate = "";
return false;
}
return true;
}
The error I'm getting is: TypeError: Date.parseDate is not a function
. As mentioned I am creating it on purpose by these lines in my validator:
tempForParseDate = Date.parseDate
Date.parseDate = "";
Stack trace:
initComponent(D="01/00/2012")ext-all.js (line 128)
initComponent()ext-all.js (line 128)
onResize()ext-all.js (line 125)
onResize(A=[Trial] Ext.EventObject {})ext-all.js (line 125)
EventManager(b=[Trial] Ext.EventObject {})ext-all.js (line 13)
getViewWidth(R=keydown charCode=0, keyCode=9)ext-base.js (line 10)
If you really want to re-write Date.parseDate
and not get a JS error, then set it to a no-op function, instead of a string.
Date.parseDate = function(){};
Or better, log when that re-written parseDate function is called so you can at least figure out if your code is doing the right thing.
Date.parseDate = function(){
console.log("Called parseDate with args ", arguments);
};