PDA

View Full Version : How do I set a validator for a field outside of the initialization? (in Controller)?



undeclared
30 Jan 2014, 9:43 AM
I find that it's not possible outside of doing the change event, which I find is insufficient and I don't particularly like it.

Is there any way to properly add the event and do validator: function(value)?

Thanks

greg.barry
5 Feb 2014, 2:36 PM
You can add a validator by simply appending a vtype config to the field reference. For instance:



var form = Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
frame: true,
bodyPadding: '5 5 0',
width: 350,
fieldDefaults: {
labelWidth: 125,
msgTarget: 'side',
autoFitErrors: false
},
defaults: {
width: 300
},
items: [{
xtype: 'textfield',
fieldLabel: 'First Name',
name: 'first',
tooltip: 'Enter your first name'
}]
});

var field = form.down('textfield');
field.vtype = 'email';


Thanks!
Greg