I'm creating a form in Django (using ModelForm). There are many checkboxes, and I want to make it so that one of these must be selected in order to submit the form. I don't mean any one checkbox, but one specific box. I can't find anything in the Django documentation. Any help would be appreciated.
Something like
from django import forms
class MyForm(forms.Form):
check = forms.BooleanField(required = True)
# your other form fields
For a BooleanField, required = True
will check if the box is checked. This is because data will only be submitted if it is checked.
Source: https://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.BooleanField
Validates that the value is True (e.g. the check box is checked) if the field has required=True.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With