Results 1 to 2 of 2

Thread: custom validator different messages for different test

  1. #1
    Touch Premium Member
    Join Date
    Mar 2012
    Posts
    115

    Default custom validator different messages for different test

    I have written a couple of custom validators, they are basically working.

    However, with confirmInstancePath I have too test.

    The value must start with another value. (working) and it must be longer that the other value indicating that it's been added too (working)

    However I would like to give different error messages for each failure

    confirmInstancePathText: 'Instance Root Path must start with the sites master path',

    or

    confirmInstancePathText: 'Please add directory path to the sites master path',

    Code:
    Ext.define('overrides.form.field.VTypes', {
        override: 'Ext.form.field.VTypes',
        
        confirmInstancePath: function(val, field) {
            if (field.siteInfoField) {
                var record = field.up('form').down('#' + field.siteInfoField).getSelectedRecord(),
                 rootPath = record.get('master_root_path');
    
    
                 return ( val.startsWith(rootPath) && (val.length > rootPath.length ) );
            }
            return true;
        },
        confirmInstancePathText: 'Instance Root Path must start with the sites master path',
    
    
        confirmPassword: function(val, field) {
            if (field.initialPassField) {
                var pwd = field.up('form').down('#' + field.initialPassField);
                return (val == pwd.getValue());
            }
            return true;
        },
    
    
        confirmPasswordText: 'Passwords do not match'
    });
    TIA
    Harry

  2. #2
    Touch Premium Member
    Join Date
    Mar 2012
    Posts
    115

    Default Figure it out

    Figured it out, can set the corresponding error message text in the method

    Code:
    Ext.define('overrides.form.field.VTypes', {
        override: 'Ext.form.field.VTypes',
        
        confirmInstancePath: function(val, field) {
            if (field.siteInfoField) {
                var record = field.up('form').down('#' + field.siteInfoField).getSelectedRecord(),
                rootPath = record.get('master_root_path');
                
                if ( !val.startsWith(rootPath) ) {
                    this.confirmInstancePathText = 'Instance Root Path must start with the sites master path';
                    return false;
                }
                if ( val.length <= rootPath.length ) {
                    this.confirmInstancePathText = 'Please add directory path to the sites master path';
                    return false;
                }
            }
            return true;
        },
        confirmInstancePathText: 'This field is required',
    
    
        confirmPassword: function(val, field) {
            if (field.initialPassField) {
                var pwd = field.up('form').down('#' + field.initialPassField);
                return (val == pwd.getValue());
            }
            return true;
        },
    
    
        confirmPasswordText: 'Passwords do not match'
    });

Posting Permissions

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