Following this thread here I was able to add a validation to a form with both radio buttons and checkboxes: if at least one option per each question is selected, the submit button is enabled.
here is the code:
$('input:submit').attr('disabled',true);
var input_groups = {}
$("input:radio, input:checkbox").each(function(){
$(this).attr('checked', false);
input_groups[this.name] = true;
});
$('input:radio, input:checkbox').change(function() {
var submission = true;
for(group in input_groups){
is_checked = !!$("[name=" + group + "]:checked").length
if(!is_checked){ submission = false;}
}
if (submission){
$("label[for='submit']").html('You are ready to submit!');
$('input:submit').attr('disabled',false);
}
});
It works, but if I accidentally deselect a checkbox, the submit button stays enabled...I am probably missing something obvious...
Any suggestion?
Thank you