I want to add a checkbox with a required field.
My code is :
<div>
<input class="input required-entry" type="checkbox" id="check" name="check" value="1" data-validate="{required:true, 'validate-one-required-by-name':true}" /> I agree to the Terms and Conditions.
</div>
But it's not working.
Thank you
1 Answer 1
You must have data-mage-init='{"validation":{}}' in your form
<form id="custom-form" data-mage-init='{"validation":{}}'>
<input class="input required-entry" type="checkbox" id="check" name="check" value="1" data-validate="{required:true, 'validate-one-required-by-name':true}" /> I agree to the Terms and Conditions.
<input type="submit" value="Submit">
</form>
Or
<form id="custom-form">
<input class="input required-entry" type="checkbox" id="check" name="check" value="1" data-validate="{required:true, 'validate-one-required-by-name':true}" /> I agree to the Terms and Conditions.
<input type="submit" value="Submit">
</form>
<script type="text/x-magento-init">
{
"#custom-form": {
"validation": {}
}
}
</script>
answered Aug 31, 2018 at 21:19
-
Thank you, can we display alert?gill– gill2018年09月04日 20:42:10 +00:00Commented Sep 4, 2018 at 20:42
-
What do you mean by alert and where ?2018年09月04日 21:19:52 +00:00Commented Sep 4, 2018 at 21:19
-
When I click on submit if checkbox is uncheck then i want to display alert ex plz agree terms and conditions.gill– gill2018年09月05日 02:20:57 +00:00Commented Sep 5, 2018 at 2:20
-
if(jQuery('#check').not(':checked').length){ alert('Not checked'); }2018年09月05日 07:46:40 +00:00Commented Sep 5, 2018 at 7:46 -
I tried but this code is not workinggill– gill2018年09月05日 13:24:05 +00:00Commented Sep 5, 2018 at 13:24
default