I have a ModelForm with the following init method:
def __init__(self, *args, **kwargs):
super(FragebogenForm, self).__init__(*args, **kwargs)
self.fields['birth_date'].widget.attrs.update({'type': 'date'})
This doesn't change the type attribute of the input tag, although it should according to the documentation (ctrl + f -> "Or if the field isn’t declared directly on the form"). If I change it to e.g. .widget.attrs.update({'placeholder': '12.12.1999'}) it works, the new placeholder appears on the page. Only setting the type to date does not work, but why?
The type of the widget is determined by the
.input_typeattribute, so:This is however often not a good idea, since other items of the widget are then not altered correctly. Normally you specify the widget in the
Metaclass:But if the widget is not a
DateInput, then likely the fieldbirth_datein your model is not amodels.DateField, so it might be better to fix this instead of solving it at the widget level.