Opened 7 years ago

Closed 7 years ago

Last modified 7 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



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':})

print form.as_ul()

# 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 7 years ago.
widgets.patch (868 bytes) - added by anonymous 7 years ago.
22290-test.diff (1.7 KB) - added by Claude Paroz 7 years ago.

Download all attachments as: .zip

Change History (6)

Changed 7 years ago by anonymous

Attachment: fields.patch added

Changed 7 years ago by anonymous

Attachment: widgets.patch added

comment:1 Changed 7 years ago by Claude Paroz

Resolution: needsinfo
Status: newclosed

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

Changed 7 years ago by Claude Paroz

Attachment: 22290-test.diff added

comment:2 Changed 7 years ago by dibrovsd@…

now i cannot reproduce too.
Thank you

comment:3 Changed 7 years ago by Claude Paroz

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