Code

Opened 7 years ago

Closed 6 years ago

#3852 closed (duplicate)

[patch] newforms SelectDateWidget fails to display saved values correctly, lacks 'blank' choices

Reported by: Jeff Hilyard <jhilyard@…> Owned by: nobody
Component: Forms Version: master
Severity: Keywords: SelectDateWidget
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

SelectDateWidget in newforms.extras.widgets displays January 1, 2007 regardless of value entered.
render() assumes the value parameter is a string but it is being passed a datetime.date.
It sets the year, month, day to None before rendering the individual select tags.

This minimally invasive patch works for me but should be rewritten by someone with knowledge of how things are supposed to be - if value is supposed to be a datetime.date then that case should probably be handled in the "try" not the "except" as I've done.

Attachments (3)

newforms_extras_widgets.diff (688 bytes) - added by Jeff Hilyard <jhilyard@…> 7 years ago.
patch to fix newforms.extras.widgets.SelectDateWidget render() bug
selectdatewidget_dashes.diff (949 bytes) - added by Jeff Forcier <reg@…> 7 years ago.
Adds initial 'dashes' choices at the top of the dropdowns, as with regular select fields
django-selectdatewidget-datetime.patch (966 bytes) - added by Simon Law <simon@…> 6 years ago.
Patch that only does coersion when value is a basestring.

Download all attachments as: .zip

Change History (9)

Changed 7 years ago by Jeff Hilyard <jhilyard@…>

patch to fix newforms.extras.widgets.SelectDateWidget render() bug

comment:1 Changed 7 years ago by Simon G. <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

Changed 7 years ago by Jeff Forcier <reg@…>

Adds initial 'dashes' choices at the top of the dropdowns, as with regular select fields

comment:2 Changed 7 years ago by Jeff Forcier <reg@…>

Sigh. Keep thinking the text field on the attachment page is going to be a file description instead of the comment body. This is what I really want to say:

I seem to be having this issue too. I don't have time right now to extensively investigate the issue, but I do want to be a parasite and attach my own diff to this ticket, for a very similar/related issue: if one wanted the fields to be blank, that's not possible at this point in time, as there are no dashes in the choice lists. My diff remedies this.

comment:3 Changed 7 years ago by Jeff Forcier <reg@…>

  • Summary changed from [patch] newforms.extras.widgets SelectDateWidget shows January 1, (first year) to [patch] newforms SelectDateWidget fails to display saved values, has no blank options

comment:4 Changed 7 years ago by Jeff Forcier <reg@…>

  • Summary changed from [patch] newforms SelectDateWidget fails to display saved values, has no blank options to [patch] newforms SelectDateWidget fails to display saved values correctly, lacks 'blank' choices

Apologies for ticket spam.

comment:5 Changed 6 years ago by Simon Law <simon@…>

Here is a patch that does the coersion only when value is a basestring.

Otherwise, we just assume it's either a datetime.date or datetime.datetime object. If it isn't, it makes sense to throw an exception.

Changed 6 years ago by Simon Law <simon@…>

Patch that only does coersion when value is a basestring.

comment:6 Changed 6 years ago by mattgrayson

  • Resolution set to duplicate
  • Status changed from new to closed

The issue of displaying saved values correctly was fixed by #5917

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.