Opened 17 months ago

Closed 17 months ago

Last modified 17 months 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 17 months ago.
widgets.patch (868 bytes) - added by anonymous 17 months ago.
22290-test.diff (1.7 KB) - added by claudep 17 months ago.

Download all attachments as: .zip

Change History (6)

Changed 17 months ago by anonymous

Changed 17 months ago by anonymous

comment:1 Changed 17 months ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to needsinfo
  • Status changed from new to closed

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

Changed 17 months ago by claudep

comment:2 Changed 17 months ago by dibrovsd@…

now i cannot reproduce too.
Thank you

comment:3 Changed 17 months ago by claudep

  • Resolution changed from needsinfo to worksforme
Note: See TracTickets for help on using tickets.
Back to Top