PDA

View Full Version : how to override getErrors validation method for masking value in datefield



nil5286
23 Aug 2012, 8:04 AM
I have put masking on my datefield using [http://www.sencha.com/forum/showthread.php?21040-InputTextMask-plugin-for-Textfield]
so the getErrors throws an error saying -

__/__/____ is not a valid date - it must be in the format m/d/Y

so i want datefield to bypass this but do the validation for allowBlank that is set for the datefieldfield.

i tried to override getErrors in my ext.define statement as shown below but it does not work.


Ext.define('MyDateField', {
extend: 'Ext.form.field.Date',
alias: 'widget.mydatefield',
allowBlank: false,
getErrors: function (value) {
console.log(value);
var errors = [];
if (this.value === "__/__/____") {
errors = [];
}
else {
errors = this.callParent(arguments);
}
return errors;
}
});

Basically i want to override getErrors method for the below line in the getErrors method is creating problem as

parseDate("__/__/____")
is creating error as in below code :


svalue = value;
value = me.parseDate(value);
if (!value) {
errors.push(format(me.invalidText, svalue, Ext.Date.unescapeFormat(me.format)));
return errors;
}

Any kind of help is appreciated.

vietits
23 Aug 2012, 3:24 PM
Try the fixed code below:


Ext.define('MyDateField', {
extend: 'Ext.form.field.Date',
alias: 'widget.mydatefield',
allowBlank: false,
getErrors: function (value) {
console.log(value);
var errors = [];
// if (this.value === "__/__/____") {
if (value !== "__/__/____") { // check 'value', not 'this.value'
errors = this.callParent(arguments);
}
return errors;
}
});