JQuery Validate: only takes the first addMethod?

Posted by Neuquino on Stack Overflow See other posts from Stack Overflow or by Neuquino
Published on 2010-04-04T18:27:44Z Indexed on 2010/04/04 18:33 UTC
Read the original article Hit count: 291

Filed under:
|
|

Hi, I need to add multiple custom validations to one form. I have 2 definitions of addMethod. But it only takes the first one... here is the code.

$(document).ready(function() {  
  $.validator.addMethod("badSelectionB",function(){  
    var comboValues = [];  
    for(var i=0;i<6;i++){
      var id="comision_B_"+(i+1);
      var comboValue=document.getElementById(id).value;
      if($.inArray(comboValue,comboValues) != 0){
        comboValues.push(comboValue);
      }else{
        return false;
      }
    } 
    return true;
  },"Seleccione una única prioridad por comisión.");
  $.validator.addMethod("badSelectionA",function(){     
    var comboValues = [];
    for(var i=0;i<6;i++){
      var id="comision_A_"+(i+1);
      var comboValue=document.getElementById(id).value;  
      if($.inArray(comboValue,comboValues) != 0){
        comboValues.push(comboValue);
      }else{
        return false;
      }
    }
    return true;
  },"Seleccione una única prioridad por comisión.");    
  $("#inscripcionForm").validate(
  {
    rules : {
      nombre : "required",
      apellido : "required",
      dni : {
        required: true,
        digits: true,
      },
      mail : {
        required : true,
        email : true,
      },        
      comision_A_6: {                       
        badSelectionA:true,
      },
      comision_B_6: {                       
        badSelectionB: true,
      }
    },
    messages : {
      nombre : "Ingrese su nombre.",
      apellido : "Ingrese su apellido.",
      dni : {
        required: "Ingrese su dni.",
        digits: "Ingrese solo números.",
      },
      mail : {
        required : "Ingrese su correo electrónico.",
        email: "El correo electrónico ingresado no es válido."
      }
    },
  });
});

Do you have any clue of what is happening?

Thanks in advance,

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery