1. #1
    Sencha Premium Member
    Join Date
    Sep 2012
    Posts
    94
    Vote Rating
    8
    Answers
    6
    zz9pa is on a distinguished road

      0  

    Default Answered: setting validator function dynamically...

    Answered: setting validator function dynamically...


    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.

  2. 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.

    Code:
    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) {
        console.log(val);
    }

  3. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,062
    Vote Rating
    215
    Answers
    486
    slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of

      0  

    Default


    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.

    Code:
    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) {
        console.log(val);
    }

Thread Participants: 1