Hi all, i'm trying to make this work; this validate is applied to a payment form, and as you can see, there are only 3 requierd inputs, if and only if
input[type=radio]:checked').val() != "CB";
wich means if user is about to pay with something else than a credit card. Following is the complete code to validate my form.
$("#paiement").validate({
errorClass: "invalid",
validClass: "success",
rules: {
referenceTypeComplementBancaire: true,
banque: {
required: function(nomBanque){
return $('#paiement input[type=radio]:checked').val() != "CB";
}
},
numeroComplementBancaire: {
required: function(numeroCompl){
return $('#paiement input[type=radio]:checked').val() != "CB";
}
},
montantComplementBancaire: {
required: function(montantCompl){
var logg = montantRentre >= panierTotal;
console.log(logg);
return montantRentre >= panierTotal;
}
}
},
messages: {
referenceTypeComplementBancaire: "",
banque:"",
numeroComplementBancaire:"",
montantComplementBancaire:""
}
});
}
Nothing hard, really. But, whats hard for me to understand is why montantComplementBancaire isn't validated, even if my console logging shows me 'true' or 'false' in the right time. What a m I doing wrong ?
----------------------------EDIT------------------------------------------
I think there's been some kind of misunderstanding, my fault. Sorry folks. Here's how the form finally looks like:
$("#paiement").validate({
errorClass: "invalid",
validClass: "success",
rules: {
referenceTypeComplementBancaire: true,
banque: {
required: function(nomBanque){
return $('#paiement input[type=radio]:checked').val() != "CB";
}
},
numeroComplementBancaire: {
required: function(numeroCompl){
return $('#paiement input[type=radio]:checked').val() != "CB";
}
},
montantComplementBancaire: {
required: function(){
var logg = panierTotal > montantRentre;
console.log(logg);
return panierTotal > montantRentre;
}
}
},
messages: {
referenceTypeComplementBancaire: "",
banque:"",
numeroComplementBancaire:"",
montantComplementBancaire:""
}
});
Where did I go wrong ? Not only do I want "montantComplementBancaire" to be validated, but I want it to be valid IF and ONLY IF its >= to panierTotal
Right now, I'm only testing wether or not to validate it, but what I'm looking for is a way to return 'valid' when montantRentre >= to panierTotal .
Am I making tjis any clearer ?