Hi all,
I'm trying to force a form field to be required based on a choice widget during validation.
def clean(self):
cleaned_data = self.cleaned_data
if cleaned_data.get('periodical') == True:
if cleaned_data.get('period_start_date') == None:
msg = _('custom message')
self._errors['period_start_date'] = ErrorList([msg])
The code example works, but there's no distinction in error messages anymore between whether period_start_date is required (thus not empty) or whether it's a proper formatted date. Since Django's validation handles this properly I'm not looking to replace this.
What I'm trying to accomplish (sort of) is setting required to True on the period_start_date field when the choicefield 'periodical' is ticked just before it runs clean(). Anybody a enlightening tip for me?
Thanx.