[CLOSED] Validators is not working

  1. #1

    [CLOSED] Validators is not working

    Hi

    In my TextField 'txtCPF', I set a Validator, as follows. It stopped working after the upgrade to version 2.x. I did not find any reference in the Changelog for changes in Validators...

    It has changed something? I'm doing something wrong?

    <ext:TextField runat="server" ID="txtCPF" FieldLabel="CPF" MaxLength="18" X="5" Y="0" Width="120px" 
       EnableKeyEvents="true" Validator="ValidaCPF_CNPJ" ValidateOnBlur="true">
       <Listeners>
          <KeyUp Fn="KeyUpHandler_CPF" />
       </Listeners>
    </ext:TextField>
    The javaScript function set in Validator
        var ValidaCPF_CNPJ = function (f, e) {
            if (f.length > 14) {
                return validatorCNPJ(f);
            } else {
                return validatorCPF(f);
            }
        };
    The code of javaScripts functions called in ValidaCPF_CNPJ
    function validatorCPF(cpf) {
        //VERIFICA SE O QUE FOI INFORMADO  NUMERO
    
        var vCpf = noMask(cpf);
        var status = false;
        var dv_informado = 0;
        var i = 0;
        var digito = [];
        var soma = 0;
        var posicao = 0;
        var dv = 0;
    
        if (vCpf.length == 0) { //se for igual a zero, no valido, mas retorno true, j que no digitou nada
            return true;
        }
    
        if (vCpf.length > 0 && vCpf.length < 11) {//se for maior que zero (iniciou a digitaao, mas menor que 11, que  o tamnho que tem que ter o cpf, retorno como invlido, sempre
            return false; 
        }
    
        if (!isNumber(vCpf)) { 
            status = false;
        }
        else {
            if (
                      (vCpf == '11111111111') || (vCpf == '22222222222') ||
                       (vCpf == '33333333333') || (vCpf == '44444444444') ||
                       (vCpf == '55555555555') || (vCpf == '66666666666') ||
                       (vCpf == '77777777777') || (vCpf == '88888888888') ||
                       (vCpf == '99999999999') || (vCpf == '00000000000')
                       ) {
                status = false;
            }
            else {
                //PEGA O DIGITO VERIFIACADOR
                dv_informado = vCpf.substr(9, 2);
                for (i = 0; i <= 8; i++) {
                    digito[i] = vCpf.substr(i, 1);
                }
                //CALCULA O VALOR DO 10º DIGITO DE VERIFICA??O
                posicao = 10;
                soma = 0;
    
                for (i = 0; i <= 8; i++) {
                    soma = soma + digito[i] * posicao;
                    posicao = posicao - 1;
                }
    
                digito[9] = soma % 11;
    
                if (digito[9] < 2) {
                    digito[9] = 0;
                }
                else {
                    digito[9] = 11 - digito[9];
                }
    
                //CALCULA O VALOR DO 11º DIGITO DE VERIFICA??O
                posicao = 11;
                soma = 0;
    
                for (i = 0; i <= 9; i++) {
                    soma = soma + digito[i] * posicao;
                    posicao = posicao - 1;
                }
    
                digito[10] = soma % 11;
    
                if (digito[10] < 2) {
                    digito[10] = 0;
                }
                else {
                    digito[10] = 11 - digito[10];
                }
                //VERIFICA SE O DV CALCULADO  IGUAL AO INFORMADO
                dv = digito[9] * 10 + digito[10];
                if (dv != dv_informado) {
                    status = false;
                }
                else
                    status = true;
            }
        }
    
        return status;
    }
    
    
    function validatorCNPJ(cnpj) {
        var vCNPJ = noMask(cnpj)
    
        if (vCNPJ.length == 0) { //se for igual a zero, no valido, mas retorno true, j que no digitou nada
            return true;
        }
    
        if (vCNPJ.length > 0 && vCNPJ.length < 14) {//se for maior que zero (iniciou a digitaao, mas menor que 11, que  o tamnho que tem que ter o cpf, retorno como invlido, sempre
            return false; 
        }
    
        if (!isNumber(vCNPJ)) { 
            return false;
        }
    
        var cnpj1 = vCNPJ.substr(0,12);
        var cnpj2 = vCNPJ.substr(12,2);
        var soma = 0;
        var digito = 0;
        var i = 0;
        var j = 0;
        var controle = "";
        var mult = "543298765432";
        
        for (j = 0; j < 2; j++) {
            soma = 0;
            for (i = 0; i < 13; i++) {
                soma = soma + cnpj1.substr(i, 1) * mult.substr(i, 1);
            }
            if (j == 1) {
                soma += (2 * digito);
            }
            digito = (soma * 10) % 11;
            if (digito == 10) {
                digito = 0;
             }
            controle = controle + digito.toString();
            mult = "654329876543";
        }
    
        return (controle == cnpj2);
        
    }
    Thanks for any help!
    Last edited by Daniil; Feb 06, 2012 at 6:09 PM. Reason: [CLOSED]
  2. #2
    Hi,

    We will fix it. Thanks for the report.

    For now please use the ={} syntax:
    Validator="={myValidator}"
  3. #3
    My fault, it just became an inner property.

    Example
    <ext:TextField runat="server">
        <Validator Fn="myValidator" />
    </ext:TextField>
    We will add a respective CHANGELOG item, thanks for the pointing it out.
    Last edited by Daniil; Jan 31, 2012 at 7:07 PM.
  4. #4
    Hello Daniil...

    Thanks for your answer...

    Worked very well.
  5. #5
    The CHANGELOG item #93:
    http://examples2.ext.net/#/Getting_S...nts/CHANGELOG/

    Thanks again for the report.

Similar Threads

  1. [CLOSED] [1.0]multiple validators on a single textfield
    By betamax in forum 1.x Premium Help
    Replies: 4
    Last Post: Mar 07, 2011, 8:32 PM
  2. Window and Validators in UpdatePanel
    By mhaberman in forum 1.x Help
    Replies: 2
    Last Post: Mar 11, 2010, 2:48 AM
  3. How can I use validators?
    By flormariafr in forum 1.x Help
    Replies: 1
    Last Post: Jan 21, 2010, 3:19 PM
  4. Validators for form controls
    By shaun in forum Feature Requests
    Replies: 2
    Last Post: Jul 20, 2009, 2:52 PM
  5. how to use validators in coolite 7
    By joydeepsen in forum 1.x Help
    Replies: 2
    Last Post: Jun 02, 2009, 8:17 AM

Posting Permissions