I have declared form, which contains DateInput. DateInput has specified format attribute. This will format field's date value. At the same time, the form will expect the same format upon validation.
My Form:
class CoolForm(forms.ModelForm):
class Meta:
model = Event
fields = ['day', 'time_from', 'time_to', 'type']
widgets = {
'day': forms.DateInput(format=('%d--%m--%Y'))
}
Template:
{{ field.as_hidden }} <!-- is rendered with wrong format: -->
<input id="id_day" name="day" type="hidden" value="2017-04-30">
{{ field }} <!-- is rendered with correct format: -->
<input id="id_day" name="day" type="text" value="30--04--2017">
Problem:
In template when I print form using field.as_hidden, format remains unaffected from form setting. It even ignores attr attribute. How can I render field as hidden, while keeping its specified date format?