Documentation / Tutorials / Tutorials & How to’s
Validating Checkbox with SPA
/ Tutorials & How to’s / Validating Checkbox with SPA
<script type="spa/axn" axn=core.run_script>
var validation_rule={}
validation_rule.order=2;
validation_rule.message="<i class='fa fa-exclamation-triangle'></i> Terms & Conditions are required!";
validation_rule.attribute='accept_checkbox';
validation_rule.fn=function(o){
if (o.el.prop('checked')) return true;
return false;
}
spa.validation_rules.push(validation_rule);
</script>
You need to add the above code to your script to add a custom validation rule.
<input name="i_am_indian" value="yes" class="" required="" accept_checkbox="yes" type="checkbox">
Finally, add the 'accept_checkbox' attribute to the checkbox that you want to make required.