It's necessary to validate if result is not null because if user type a invalid "month / year", result will equal null, and an exception will be throw at line 5
Ext.form.field.Date.override({
safeParse: function (value, format) {
var result = this.callParent(arguments);
if (result != null && this.type == "month") {
return Ext.Date.getFirstDateOfMonth(result);
}
return result;
}
});
Daniil, i noticed that safeParse is called 6 times when a date is selected. I think that this could be optimized?.
Going further, if you type a invalid month / year, and then click on trigger, safeParse is called
hundreds times.
So, i would set that the field is not editable if type equals month, which prevents the issue presented above.
Ext.form.field.Date.override({
initComponent : function(){
this.callParent(arguments);
if (this.type == "month") {
this.editable = false;
}
},
safeParse: function (value, format) {
var result = this.callParent(arguments);
if (result != null && this.type == "month") {
return Ext.Date.getFirstDateOfMonth(result);
}
return result;
}
});