Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#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 Alex Lemann, 14 years ago

Triage Stage: UnreviewedAccepted

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".

comment:2 by Alex Lemann, 14 years ago

Owner: changed from nobody to Alex Lemann
Status: newassigned

comment:3 by gptvnt, 14 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 Alex Lemann, 14 years ago

Owner: Alex Lemann removed
Status: assignednew

This still shows up for me when I explicitly set USE_L10N=True in settings.py but not otherwise.

comment:5 by Mitar, 14 years ago

As I reported, the problem is only with USE_L10N set to True (default is False).

comment:6 by Ramiro Morales, 14 years ago

Owner: set to Ramiro Morales
Resolution: fixed
Status: newclosed

In [15416]:

(The changeset message doesn't reference this ticket)

comment:7 by Ramiro Morales, 14 years ago

In [15417]:

[1.2.X] Fixed #13968 -- Fixed SelectDateWidget processing of an invalid date input value when USE_L10N is on, for consistency with its behavior when USE_L10N=False (now the form field reports the validation error in both cases). Thanks mitar for the report.

Backport of [15416] from trunk

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