#22290 closed Bug (worksforme)
Forms DateField show_hidden_initial USE_L10N = False and custom DATE_INPUT_FORMATS
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Forms | Version: | 1.6 |
Severity: | Normal | Keywords: | DateField USE_L10N hidden_initial DATE_INPUT_FORMATS |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi.
if settings is:
- USE_L10N = False
- DATE_INPUT_FORMATS = ('%d.%m.%Y', '%Y-%m-%d')
then format in DateInput and HiddenInput (default hidden_widget for DateField) is different:
- DateInput: '01.01.2014'
- HiddenInput: '2014-01-01'
Field._has_changed('2014-01-01', '2014-01-01') always return True in form.changed_data
For default DATE_INPUT_FORMATS, DateInput use '%Y-%m-%d' (DATE_INPUT_FORMATS[0] for USE_L10N = False)
But if DATE_INPUT_FORMATS[0] != '%Y-%m-%d'
format HiddenInput != format DateInput
Test case:
from django import forms from datetime import date class TestForm(forms.Form): date_field = forms.DateField(show_hidden_initial=True) form = TestForm(initial={'date_field': date.today()}) print form.as_ul()
Fix:
# add HiddenDateInput
class HiddenDateInput(forms.DateInput):
is_hidden = True
input_type = 'hidden'
# set HiddenDateInput for default hidden_widget in DateField
class DateField(fields.DateField):
hidden_widget = widgets_custom.HiddenDateInput
Attachments (3)
Change History (6)
by , 11 years ago
Attachment: | fields.patch added |
---|
by , 11 years ago
Attachment: | widgets.patch added |
---|
comment:1 by , 11 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
by , 11 years ago
Attachment: | 22290-test.diff added |
---|
comment:3 by , 11 years ago
Resolution: | needsinfo → worksforme |
---|
I cannot reproduce that issue, see the test I'm attaching.