Reputation: 23322
For some reason, Django is not letting pass the parameter required=False
to my form fields.
This is my form:
class InstrumentSearch(forms.ModelForm):
groups = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, required=False)
time = forms.TimeInput(required=False)
date = forms.DateField(required=False)
notes = forms.TextInput(required=False)
The error is on the line
time = forms.TimeInput(required=False)
According to the Django Documentation here, this should absolutely work.
Upvotes: 3
Views: 20128
Reputation: 19186
Instead of using required
, try using blank
instead. blank=False
means it's not required.
time = forms.TimeInput(blank=True)
Upvotes: 4
Reputation: 15887
Looks to me like TimeInput inherits from Widget (via TextInput), which accepts attributes in one dictionary as the attrs
argument. The examples with TextInput show use of required:
>>> name = forms.TextInput(attrs={'required': False})
By contrast, Field subclasses such as TimeField and CharField do accept keyword arguments like you use.
Upvotes: 0