I am trying to do this job; this validate applies to the payment form, and, as you can see, there are only 3 inputs, if and only if
input[type=radio]:checked').val() != "CB";
this means that the user is about to pay something else but a credit card. Below 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 complicated, really. But, itβs hard for me to understand why montantComplementBancaire is not checked, even if my console logging shows me βtrueβ or βfalseβ at the right time. What am I doing wrong?
---------------------------- EDIT ------------------ --- ---------------------
I think there was some misunderstanding, my fault. Sorry people. Here's what the form 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 am I wrong? Not only do I want the "montantComplementBancaire" to be checked, but I want it to be a valid IF and ONLY IF it> = to panierTotal
Right now, I'm testing only or not testing it, but what I'm looking for is a way to return "valid" when montantRentre> = to panierTotal.
Am I making it clearer?