PDA

View Full Version : Way to override Model's validations?



estesbubba
7 May 2012, 8:58 AM
We use overrides to customize our app for each client. I have this and see the dynamic loading is loading it, but it doesn't work. Any ideas?



Ext.define('Csg.client.model.CreditCardPayment', {


override: 'Csg.model.CreditCardPayment',


config: {


validations: [{
type: 'format',
field: 'securityCode',
matcher: /.*/
}]
}
});

estesbubba
7 May 2012, 9:22 AM
Don't know if it's the best way but this works:



Ext.define('Csg.client.model.CreditCardPayment', {


override: 'Csg.model.CreditCardPayment',


validate: function(options) {
var me = this,
errors = me.callParent();


return (errors.removeAll(errors.getByField('securityCode')));
}
});

estesbubba
14 May 2012, 5:56 AM
Here is what I came up with. Still don't love it but it appears you can't override validations in config for a model. Would love to hear any feedback.



Ext.define('Csg.client.model.CreditCardPayment', {


override: 'Csg.model.CreditCardPayment',


overrideValidations: {
remove: [
'securityCode-format'
],
update: {
'authorizedPaymentAmount-format': {
matcher: /^\d+\.?\d{2}$/,
message: Csg.text('mobile.validation.format.message')
}
}
},


constructor: function() {
var me = this,
validations;


me.callParent(arguments);
validations = me.validations;


Ext.each(me.overrideValidations.remove, function(item) {
validations.removeAtKey(item);
}, me);


Ext.iterate(me.overrideValidations.update, function(key, value) {
Ext.apply(validations.getByKey(key), value);
}, me);
}
});