Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #1
    Sencha User
    Join Date
    Apr 2007
    Posts
    172
    Vote Rating
    1
    medusadelft is on a distinguished road

      0  

    Default [4.0.1] Custom validation function appears to run multiple times

    [4.0.1] Custom validation function appears to run multiple times


    Hi,

    I've got a form with a custom validation function (checkEmailAddress) for a textfield (email_addres). I've set validateOnBlur to true en validateOnChange to false (see code below).
    On form display this function is called 6 times. Is this correct or did I made a mistake?

    PHP Code:
    Ext.define('EX.view.member.Edit', {
        
    extend'Ext.window.Window'
        
    alias 'widget.memberedit'
     
        
    title 'Edit Member'
        
    layout'fit'
        
    autoShowtrue,
        
    modaltrue,
     
        
    initComponent: function() {

            
    this.items = [ 
                { 
                    
    xtype'form'
                    
    bodyPadding10,
                    
    submitEmptyTextfalse,
                    
    defaults: {
                        
    msgTarget'side'
                    
    },

                    
    items: [ 
                        {
                            
    xtype'textfield',
                            
    name'initials',
                            
    fieldLabel'Initials',
                            
    emptyText'Please enter the initials',
                            
    focusOnToFronttrue,
    //                        enforceMaxLength: true,
                            
    maxLength20,
                            
    maxLengthText'The entered initials exceeds the reserved database space!',
                            
    width200
                        
    },
                        {
                            
    xtype'textfield'
                            
    name 'firstname'
                            
    fieldLabel'First name',
    //                        enforceMaxLength: true,
                            
    maxLength50,
                            
    maxLengthText'The entered first name exceeds the reserved database space!',
                            
    emptyText'Please enter the first name'
                        
    }, 
                        {
                            
    xtype'textfield'
                            
    name 'middlename'
                            
    fieldLabel'Middle name',
                            
    maxLength20,
                            
    maxLengthText'The entered initials exceeds the reserved database space!',
                            
    width200
                        
    }, 
                        {
                            
    xtype'textfield'
                            
    name 'lastname'
                            
    fieldLabel'Last name',
                            
    allowBlankfalse,
                            
    blankText'This field can not be blank',
                            
    emptyText'Please enter the last name',
                            
    minLength2,
                            
    minLengthText'The entered last name seems to be invalid!',
                            
    maxLength200,
                            
    maxLengthText'The entered initials exceeds the reserved database space!',
                            
    width350
                        
    },
                        {
                            
    xtype'combo'
                            
    ,name'countries_id'
                            
    ,id'countries_id'
                            
    ,fieldLabel'Country'
                            
    ,store'Countries'
                            
    ,queryMode'local'
                            
    ,displayField'name'
                            
    ,valueField'id'
                            
    ,forceSelectiontrue
                            
    ,allowBlankfalse
                            
    ,blankText'This field can not be blank'
                            
    ,emptyText'Please select a country'
                        
    },

                        
    objFormEmptyLine,

                        {
                            
    xtype'fieldcontainer',
                            
    fieldLabel'Gender',
                            
    defaultType'radiofield',
                            
    defaults: {
                                
    flex1
                            
    },
                            
    layout'hbox',
                            
    items: [
                                {
                                    
    name'gender',
                                    
    boxLabel"<div class='mcc-icon-female-icon mcc-icon-inline' alt='female' title='female'></div> Female",
                                    
    inputValue0,
                                    
    id'gender1'
                                
    },
                                {
                                    
    name'gender',
                                    
    boxLabel"<div class='mcc-icon-male-icon mcc-icon-inline' alt='male' title='male'></div> Male",
                                    
    inputValue1,
                                    
    id'gender2'
                                
    }
                            ]
                        },
                        {
                            
    xtype'datefield'
                            
    ,fieldLabel'Date of birth'
                            
    ,name'date_of_birth'
                            
    ,formatdefaultDateFormat
                            
    ,altFormatdefaultDbDateFormat
                            
    ,emptyText'Please select the date of birth'
                            
    ,showTodayfalse
                            
    ,width200
                        
    },

                        
    objFormEmptyLine,

                        { 
                            
    xtype'textfield'
                            
    ,fieldLabel'Email'
                            
    ,name 'email_address'
                            
    ,id'email_address' 
                            
    ,invalidText'The entered email address is invalid!'
                            
    ,vtype'email'
                            
    ,emptyText'Please enter the member\'s email address'
                            
    ,maxLength250
                            
    ,maxLengthText'The entered email address exceeds the reserved database space!'
                            
    ,width350
                            
    ,validateOnBlurtrue
                            
    ,validateOnChangefalse
                            
    ,validatorthis.checkEmailAddress
                        
    },
                        
    objFormEmptyLine,
                        {
                            
    xtype'fieldset',
                            
    title'Allow login',
                            
    name'allow_login_frm',
                            
    checkboxName'allow_login',
                            
    checkboxToggletrue,
    //                        collapsed: false,
                            
    layout'anchor',
                            
    items: [
                                {
                                    
    xtype'textfield'
                                    
    ,fieldLabel'Login name'
                                    
    ,name'login_name'
                                    
    ,id'login_name'
                                    
    ,emptyText'Please enter a unique login name'
                                    
    ,maxLength100
                                    
    ,maxLengthText'The entered login name exceeds the reserved database space!'
                                    
    ,width300
                                    
    ,msgTarget'side'
                                
    },
                                {
                                    
    xtype'textfield',
                                    
    name'login_pwd',
                                    
    fieldLabel'Password',
                                    
    inputType'password',
                                    
    emptyText'Please enter a strong password',
                                    
    maxLength100,
                                    
    maxLengthText'The entered login name exceeds the reserved database space!',
                                    
    width300
                                
    }
                            ]
                        }
                    ] 
                } 
            ]; 

            
    this.buttons = [
                {
                    
    text'Save'
                    
    ,action'save'
                
    },
                {
                    
    text'Cancel'
                    
    ,action'cancel'
                
    }
            ];

            
    this.callParent(arguments);
        }


        ,
    checkEmailAddress: function(val) {
            var 
    form this.up('form');
            var 
    tmp form.getRecord();

            var 
    tmpFld form.form.findField('email_address');
            if (
    tmpFld.originalValue == undefinedtmpFld.originalValue '';
            if (
    tmpFld.originalValue != val && val.length 0) {
                var 
    tmpStore Ext.data.StoreManager.lookup('Members');
                var 
    result tmpStore.find('email_address'val0falsefalsetrue);

                if (
    result > -1) return 'This email address is already used!\nPlease enter a new one.';
            }
            return 
    true;
        }

    }); 

    Maurice.

  2. #2
    Ext JS Premium Member
    Join Date
    Jan 2012
    Posts
    132
    Vote Rating
    0
    shailykamboj is on a distinguished road

      0  

    Default


    hello Maurice !
    Did you find solution to your problem ? i am facing same issues , i have ValdiateOnChange as false but then too validator is getting called on every change . As i understand this config , if it is set to false then it should be called only before submit . Any idea ?


    Thanks

  3. #3
    Sencha User
    Join Date
    Jun 2012
    Posts
    82
    Vote Rating
    1
    dr-dan is on a distinguished road

      0  

    Default


    If you don't want live validation you may want to turn off validateOnBlur in conjuncton with this (validateOnChange).