Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#22290 closed Bug (worksforme)

Forms DateField show_hidden_initial USE_L10N = False and custom DATE_INPUT_FORMATS

Reported by: dibrovsd@… 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)

fields.patch (1.2 KB ) - added by anonymous 10 years ago.
widgets.patch (868 bytes ) - added by anonymous 10 years ago.
22290-test.diff (1.7 KB ) - added by Claude Paroz 10 years ago.

Download all attachments as: .zip

Change History (6)

by anonymous, 10 years ago

Attachment: fields.patch added

by anonymous, 10 years ago

Attachment: widgets.patch added

comment:1 by Claude Paroz, 10 years ago

Resolution: needsinfo
Status: newclosed

I cannot reproduce that issue, see the test I'm attaching.

by Claude Paroz, 10 years ago

Attachment: 22290-test.diff added

comment:2 by dibrovsd@…, 10 years ago

now i cannot reproduce too.
Thank you

comment:3 by Claude Paroz, 10 years ago

Resolution: needsinfoworksforme
Note: See TracTickets for help on using tickets.
Back to Top