#22290: Forms DateField show_hidden_initial USE_L10N = False and custom
DATE_INPUT_FORMATS
-------------------------+-------------------------------------------------
     Reporter:           |      Owner:  nobody
  dibrovsd@…             |     Status:  new
         Type:  Bug      |    Version:  1.6
    Component:  Forms    |   Keywords:  DateField USE_L10N hidden_initial
     Severity:  Normal   |  DATE_INPUT_FORMATS
 Triage Stage:           |  Has patch:  1
  Unreviewed             |      UI/UX:  0
Easy pickings:  0        |
-------------------------+-------------------------------------------------
 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

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22290>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/061.ea35d7dc7b618b9011b09fbc35ecf348%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to