Results 1 to 2 of 2

Thread: setting validator function dynamically...

  1. #1
    Sencha Premium Member
    Join Date
    Sep 2012
    Posts
    135
    Answers
    9
    Vote Rating
    11
      0  

    Default 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,154
    Answers
    501
    Vote Rating
    247
      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);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •