I am using the following code to validate that I have at least one checkbox selected but I have a problem.
JS
$("#btn_enviar").click(function() {
var invalido = 0;
$(".item").each(function( ) {
if ($(this).find("select").val() == 1) {
var cont = 0;
$(this).find("input:checkbox, input:radio").each(function() {
if($(this).is(":checked")){
cont++;
}
});
}
if(cont < 1){
$(this).find(".text-error-check").show();
$(this).find(".dynamicform_inner").css({
"border": "2px solid #dd4b39",
"background-color": "white"
});
invalido = 1;
}
});
});
');
For example, if I send the data first without having a selected checkbox it works for me but it ignores the other validations of the rules and I only get the selection error, if I then select a checkbox and send the data again, the validations of the rules of the model work.
First send
Second send
I have tried to do it with the rules in my model but have not been successful. How can I include it together with the other rules of the model?
P.D: I am using the dynamic form to generate the checkboxes and inputs.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…