#13968 closed (fixed)
SelectDateWidget does not validate chosen date
| Reported by: | Mitar | Owned by: | Ramiro Morales |
|---|---|---|---|
| Component: | Forms | Version: | 1.2 |
| Severity: | Keywords: | ||
| Cc: | mmitar@… | Triage Stage: | Accepted |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
SelectDateWidget does not validate chosen date and does not show an error to the user about invalid date (like 31 February) but silently discards it and resets/nullify the value. So user does not get any feedback and possibility to correct the date.
This is with USE_L10N set to True.
The problem is probably that any ValueError errors from datetime are silently discarded and input date is taken as it is invalid format not invalid date.
Change History (7)
comment:1 by , 15 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 15 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 15 years ago
Looks like it's fixed in the latest trunk. Following the same example, I get the following -
>>> from django import forms
>>> from django.forms.extras.widgets import SelectDateWidget
>>> class DateForm(forms.Form):
... date = forms.DateField(widget=SelectDateWidget)
...
>>> form = DateForm({'date_month':'2', 'date_day':'31', 'date_year':'2010'})
>>> form.is_valid()
False
>>> form.errors
{'date': [u'Enter a valid date.']}
comment:4 by , 15 years ago
| Owner: | removed |
|---|---|
| Status: | assigned → new |
This still shows up for me when I explicitly set USE_L10N=True in settings.py but not otherwise.
comment:5 by , 15 years ago
As I reported, the problem is only with USE_L10N set to True (default is False).
comment:6 by , 15 years ago
| Owner: | set to |
|---|---|
| Resolution: | → fixed |
| Status: | new → closed |
In [15416]:
(The changeset message doesn't reference this ticket)
Here is code to reproduce the bug:
In [1]: from django import forms In [2]: from django.forms.extras.widgets import SelectDateWidget In [3]: class DateForm(forms.Form): ...: date = forms.DateField(widget=SelectDateWidget) ...: In [4]: form = DateForm({'date_month': '2', 'date_day': '31', 'date_year': '2010' }) In [5]: form.is_valid() Out[5]: False In [6]: form.errors Out[6]: {'date': [u'This field is required.']}At the very least, the error here should be "invalid date".