Make Checkbox Required on Web Form
Using JS/Jquery
Probuse Admin
Start writing here...
Add checkbox on template/page like contact us form and make it mandatory:
=========================================================
<div class="form-group form-field o_website_form_required_custom">
<input type="checkbox" id="opt_out" name="opt_out" t-attf-value="#{opt_out or ''}" required="required"/>
</div>
=========================================================
Add script inside form tag (Before </form>).
<script type="text/javascript">
$(document).ready(function (e) {
$('.o_website_form_send').click(function() {
if (!$("#opt_out").is(":checked")) {
e.preventDefault();
}
});
});
</script>
=========================================================
Tips: 1. o_website_form_send => Name of class on button. "." specify class and if "#" specify id. 2. opt_out => Id of checkbox. 3. e.preventDefault(); => Jquery