View Full Version : setting validator function dynamically...

8 Mar 2013, 8:22 AM
I know I can set a validator function via a 'config' when I create my fields..
Is there anyway to change the validator *after* the field has been created ?

In my case - there may be some fields in my forms which are generated by Ext.create(...), and I want to apply the validations to them after they have been created.

8 Mar 2013, 9:44 AM
Looks like you can just set the validator function any 'ol time. Works in 4.1.3 at least - I suspect it works the same in past versions.

var f = Ext.create('Ext.form.Panel', {
title: 'Contact Info',
width: 300,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Name',
allowBlank: false // requires a non-empty value
}, {
xtype: 'textfield',
name: 'email',
fieldLabel: 'Email Address',
vtype: 'email' // requires value to be a valid email address format

f.down('textfield').validator = function (val) {