Opened 9 years ago
Closed 9 years ago
#27724 closed Bug (fixed)
SelectDateWidget clears date and month if year is not selected
| Reported by: | tpazderka | Owned by: | Adonys Alea Boffill |
|---|---|---|---|
| Component: | Forms | Version: | 1.10 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | yes |
| Easy pickings: | no | UI/UX: | no |
Description
If year is not selected in SelectDateWidget, then all the inputs are cleared as opposed to a state where date or month is missing.
The issue is that SelectDateWidget.value_from_datadict does not return a value that would be matched by SelectDateWidget.date_re.
The returns from SelectDateWidget.value_from_datadict should probably be formatted as follows
return '{:04d}-{:d}-{:d}'.format(y, m, d)
Attachments (1)
Change History (11)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 9 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
by , 9 years ago
| Attachment: | ticket_27724.diff added |
|---|
comment:4 by , 9 years ago
| Has patch: | set |
|---|
To fix this ticket I changed the regular expresion of SelectDateWidget.date_re from:
date_re = re.compile(r'(\d{4})-(\d\d?)-(\d\d?)$')
to:
date_re = re.compile(r'(\d{4}|0)-(\d\d?)-(\d\d?)$')
I added 0 to the year possible value because 0 is set as default value of year's Select, and I kept the restriction of 4 digits for a valid year value. I added tests for the SelectDateWidget.date_re expression.
comment:5 by , 9 years ago
Could you please send a pull request rather than attaching a patch to the ticket?
comment:6 by , 9 years ago
| Patch needs improvement: | set |
|---|
comment:8 by , 9 years ago
I added the pull request... https://github.com/django/django/pull/8108, I hope to cover with all expectations.
comment:9 by , 9 years ago
Added PR (https://github.com/django/django/pull/8206) with non regressions tests suggested by Tim!
Another option would be to modify
SelectDateWidget.date_reto math the output fromvalue_from_datadict