[CLOSED] [1.0]multiple validators on a single textfield

  1. #1

    [CLOSED] [1.0]multiple validators on a single textfield

    I have the following control on a page:
     
    <tbm:VMSTextField ID="txtNewPW" 
        runat="server" 
        InputType="Password" 
        LabelID="new_password" 
        AllowBlank="false" 
        MaxLength="50" 
        Validator="newPWValidator"
        ValidateTo="txtOldPw" >
    </tbm:VMSTextField>
    It also has this codebehind property assignment:
    code behind:
    txtNewPW.Vtype = "pwSecurityHigh"
    And this is the custom VType which tests password strength:
    javascript:

    Ext.apply(Ext.form.VTypes,{    
        pwSecurityHigh: function (v) {         
        var highSecPattern = new RegExp('(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,})$');        
        var res = highSecPattern.test(v);        
        return res;    
    }});
    The problem is that line 2 below returns undefined for this.getErrors(value)[0]. The value I need is at [1].
    extjs:
    validateValue: function (value) { 
         var error = this.getErrors(value)[0]; 
         if (error == undefined) { 
             return true; 
         } else { 
             this.markInvalid(error); 
             return false; 
         } 
     }
    Obviously this is because there are 2 validations. Any way around this? I tried overriding the ValidateValue function but did not succeed. Perhaps i could combine the 2?
    The other validation routine compares this field to another for equality
    var newPWValidator = function (value) {
                if (Ext.getCmp('txtOldPW')) {
                    var validateToValue = Ext.getCmp(this.validateTo).getRawValue();
                    if (value == validateToValue && value !== '' && validateToValue !== '') {
                        BtnRibWin1_btn1.disable();
                        return PageStrings.old_and_new_passwords_can_not_match;
                    }
                    BtnRibWin1_btn1.enable();
                    return true;
                }
            }
    The problem I first see with combining is that oldPw does not always exist, and there are also multiple password strengths to test for. Presently the custom vtype functions are located in a global js file.
    Last edited by Daniil; Mar 07, 2011 at 9:09 PM. Reason: [CLOSED]
  2. #2
    Hi,

    The .Validator function should return 'true' if the value is valid or string error message if the value is invalid.
    http://dev.sencha.com/deploy/dev/doc...mber=validator

    Well, returning 'true' from .Validator function when 'txtOldPW' is not exists should solve the problem.

    Example
    var newPWValidator = function (value) {
        if (Ext.getCmp('txtOldPW')) {
            var validateToValue = Ext.getCmp(this.validateTo).getRawValue();
            if (value == validateToValue && value !== '' && validateToValue !== '') {
                BtnRibWin1_btn1.disable();
                return PageStrings.old_and_new_passwords_can_not_match;
            }
            
            BtnRibWin1_btn1.enable();
        }
        return true;
    }
  3. #3
    I believe you've misunderstood the problem.
    Yes it does, but not at the expected index. validateValue is part of the Extjs .Validate and
    this line: var error = this.getErrors(value)[0]; is where the error message is returned when false, empty when true.
    The problem is (or seems to be) that because I have 2 validators, then only one actually returns a msg... the other is at index [1] and is not checked. Only [0] is checked. If my field passes validation in the first validator and fails in the second, validateValue is only able to show the first.. which is true.
  4. #4
    Ok, lets consider the following example.

    1. Type something, not "Validator". It fails both validations, and the 'Validator' error is showed because it has a higher priority.
    2. Type "Validator". It passes Validator validation, but fails VType validation and the VType error message is showed.

    So, it works as expected.

    Only one thing I can't see in your code, it;s VtypeText. Did you defined it? If no, please define. I'm pretty sure it will solve the problem.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    
        <ext:ResourcePlaceHolder runat="server" />
        <script type="text/javascript">
            Ext.apply(Ext.form.VTypes, {   
                myVType : function (v) {
                    return v === "VType";
                }
            });
            
            var myValidator = function (v) {
                if (v === "Validator") {
                        return true;
                    }
                return "Validator validation fails!"
            }
        </script>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:TextField 
            runat="server" 
            Validator="myValidator" 
            Vtype="myVType" 
            VtypeText="VType validation fails" 
            />
        </form>
    </body>
    </html>
  5. #5

    [CLOSED]

    Thanks Danil. I redid my code, all in markup, and then moved things one by one back to code behind, and everything works as expected now. Still not sure why my VTypeText was showing up in the [1] index of the error obj, except that it may be that if the primary validator has a issue then the secondary doesn't work either. At any rate, seeing your code work showed me I had a problem which could be solved with diligence.

Similar Threads

  1. [CLOSED] Multiple partial views on single page
    By machinableed in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: May 03, 2012, 9:06 AM
  2. Adding multiple partial views in single call
    By Tallmaris in forum 1.x Help
    Replies: 0
    Last Post: Sep 14, 2011, 1:26 PM
  3. Multiple vType on a Single Control
    By huzzy143 in forum 1.x Help
    Replies: 2
    Last Post: Sep 09, 2011, 3:39 PM
  4. [CLOSED] multiple validations in single field
    By rnfigueira in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 23, 2011, 5:45 PM
  5. Multiple ext controls in single anchor (or workaround)
    By dlouwers in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Dec 04, 2008, 12:53 PM

Posting Permissions