-
7 May 2012 8:58 AM #1
Way to override Model's validations?
Way to override Model's validations?
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?
Code:Ext.define('Csg.client.model.CreditCardPayment', { override: 'Csg.model.CreditCardPayment', config: { validations: [{ type: 'format', field: 'securityCode', matcher: /.*/ }] } });
-
7 May 2012 9:22 AM #2
Don't know if it's the best way but this works:
Code: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'))); } });
-
14 May 2012 5:56 AM #3
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.
Code: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); } });


Reply With Quote