#12986 closed (fixed)
SelectDateField doesn't repost data when USE_L10N = True and LANGUAGE_CODE = 'nl'
Reported by: | Owned by: | bmihelac | |
---|---|---|---|
Component: | Forms | Version: | 1.2-beta |
Severity: | Keywords: | ||
Cc: | bmihelac | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hello,
If validation of a form fails, SelectDateField doesn't repost the data correctly, when USE_L10N = True and LANGUAGE_CODE = 'nl'.
For example, if I entered 2 februari 2010, the form redisplays as 1 januari 2010
Attachments (4)
Change History (24)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
This is actually not restricted to the given settings (USE_L10N = True
and LANGUAGE_CODE = 'n1'
) as stated above. To clarify, if a form doesn't validate, the widget doesn't hold the value that was submitted resetting the month and date to January 1, with the year being the current year. I only noticed the latter behavior since I've been using said widget since early-2009.
comment:3 by , 15 years ago
#-- forms.py
from django.forms.extras import SelectDateWidget
class ConceptTripForm(forms.Form):
required = forms.CharField()
date = forms.DateField(label="Datum", required=True, widget=SelectDateWidget())
#-- views.py
from forms import ConcepTripForm
@render_to('trips/formtest.html')
def form_test(request):
if request.POST:
form = ConceptTripForm(request.POST)
if form.is_valid():
print "Wow!"
return HttpResponseRedirect('/')
else:
form = ConceptTripForm()
return {'form': form,}
#-- formtest.html
<form action="." method="POST">
<table>{% csrf_token %}
{{ form }}
<input type="submit" name="OK" value="OK">
</table>
</form>
When I enter:
Required: (nothing)
Datum: 2 februari 2011
What I get is a form error, obviously. But unfortunately, the date has been reset. So after the error the form shows:
- Dit veld is verplicht. (Translation: This field is required.)
Required: (nothing)
Datum: 1 januari 2010
So the date I entered is gone.
I hope this description helps. Thanks!
comment:4 by , 15 years ago
Wow, that did look ugly, didn't it? Let's retry:
#-- forms.py from django.forms.extras import SelectDateWidget class ConceptTripForm(forms.Form): required = forms.CharField() date = forms.DateField(label="Datum", required=True, widget=SelectDateWidget()) #-- views.py from forms import ConcepTripForm @render_to('trips/formtest.html') def form_test(request): if request.POST: form = ConceptTripForm(request.POST) if form.is_valid(): print "Wow!" return HttpResponseRedirect('/') else: form = ConceptTripForm() return {'form': form,} #-- formtest.html <form action="." method="POST"> <table>{% csrf_token %} {{ form }} <input type="submit" name="OK" value="OK"> </table> </form>
When I enter:
Required: (nothing)
Datum: 2 februari 2011
What I get is a form error, obviously. But unfortunately, the date has been reset. So after the error the form shows:
- Dit veld is verplicht. (Translation: This field is required.)
Required: (nothing)
Datum: 1 januari 2010
So the date I entered is gone.
I hope this description helps. Thanks!
comment:5 by , 15 years ago
milestone: | → 1.2 |
---|---|
Triage Stage: | Unreviewed → Accepted |
Problem confirmed with the same code provided. I can only see it if USE_L10N is enabled and LANGUAGE_CODE='nl'. If I disable L10N or use a different language code, I don't see the problem.
comment:6 by , 15 years ago
I see the same problem when LANGUAGE_CODE is "fr" or "es". It's working for me for "en-us"
comment:7 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:8 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:9 by , 15 years ago
Status: | new → assigned |
---|
by , 15 years ago
Attachment: | 12986.diff added |
---|
comment:10 by , 15 years ago
Has patch: | set |
---|---|
Needs tests: | set |
comment:11 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
by , 15 years ago
Attachment: | 12986-2.diff added |
---|
comment:12 by , 15 years ago
Cc: | added |
---|
Attached is patch with tests.
Code is slightly changed from original so it would also properly redisplay invalid dates when USE_L10N = True given that default input format consist of %Y, %m and %d format directives.
by , 15 years ago
Attachment: | 12986-2.2.diff added |
---|
comment:13 by , 15 years ago
Tests moved from widgets.py to to proper extra.py.
Changed to always display blank choices for selects, so partial selection can be made and redisplayed.
by , 15 years ago
Attachment: | 12986-3.diff added |
---|
comment:14 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:15 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:16 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:17 by , 15 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Please don't close tickets that haven't been fixed in trunk.
comment:18 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
comment:19 by , 15 years ago
This ticket has been closed because the critical bug (getting the date wrong on resubmit) has been fixed. However, the fix isn't really complete; #13427 documents an edge case where the current implementation is lacking.
Excuse the confusion, but do you mean the SelectDateWidget in
django.forms.extras.widgets
? Would you mind providing a test case or a simple example what fails for you?