Opened 7 years ago

Closed 7 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)

ticket_27724.diff (2.7 KB ) - added by Adonys Alea Boffill 7 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 by tpazderka, 7 years ago

Another option would be to modify SelectDateWidget.date_re to math the output from value_from_datadict

date_re = re.compile(r'(\d+)-(\d\d?)-(\d\d?)$')

comment:2 by Tim Graham, 7 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Adonys Alea Boffill, 7 years ago

Owner: changed from nobody to Adonys Alea Boffill
Status: newassigned

by Adonys Alea Boffill, 7 years ago

Attachment: ticket_27724.diff added

comment:4 by Adonys Alea Boffill, 7 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 Tim Graham, 7 years ago

Could you please send a pull request rather than attaching a patch to the ticket? Also, it would be better to include non-regression tests (the ones that already pass without the fix) in a separate patch/commit so it's more clear which cases this fixes.

Last edited 7 years ago by Tim Graham (previous) (diff)

comment:6 by Tim Graham, 7 years ago

Patch needs improvement: set

comment:7 by Adonys Alea Boffill, 7 years ago

OK Tim!, I'll work on that this week... thanks for your comment.

comment:8 by Adonys Alea Boffill, 7 years ago

I added the pull request... https://github.com/django/django/pull/8108, I hope to cover with all expectations.

comment:9 by Adonys Alea Boffill, 7 years ago

Added PR (https://github.com/django/django/pull/8206) with non regressions tests suggested by Tim!

comment:10 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In cd2ad26c:

Fixed #27724 -- Fixed SelectDateWidget redisplay if a year isn't chosen.

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