Jquery / Forms / Conditional form validation
Conditional Validation
-
STEPS
in view
in jquery
$('body').on("change", ".religion_id" , function() { var identifier=$(".religion_id option:selected").attr("data-identifier"); $('#diocese').val(''); $('#parish').val(''); if(identifier=="Christian"){ $('#diocese').show(); $('#diocese').addClass('mandatory'); $('#parish').hide(); $('#parish').removeClass('mandatory'); } else{ $('#diocese').hide(); $('#diocese').removeClass('mandatory'); $('#parish').hide(); $('#parish').removeClass('mandatory'); } });