I’d like to have a field which is required conditionally based on setting a boolean value to True or False.
What should I return to set required =True if is_company is set to True?
class SignupFormExtra(SignupForm):
is_company = fields.BooleanField(label=(u"Is company?"),
required=False)
NIP = forms.PLNIPField(label=(u'NIP'), required=False)
def clean(self):
if self.cleaned_data.get('is_company', True):
return ...?
else:
pass
Check the Chapter on Cleaning and validating fields that depend on each other in the documentation.
The example given in the documentation can be easily adapted to your scenario: