Opened 3 years ago

Closed 3 years ago

#22684 closed New feature (fixed)

SelectDateWidget's none_value is not changeable

Reported by: Daniel Samuels Owned by: Guillaume Pannatier
Component: Forms Version: master
Severity: Normal Keywords:
Cc: Daniel Samuels Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: yes

Description

If you want to use a SelectDateWidget to represent your DateField, your output will have "---" as the default option text, this text is not changeable to suit the needs of each individual application in the same way that other fields can have their default set. I believe this widget should gain a new attribute such as empty_label to match standard ChoiceFields.

Change History (18)

comment:1 Changed 3 years ago by Daniel Samuels

Cc: Daniel Samuels added

comment:2 Changed 3 years ago by Claude Paroz

Easy pickings: set
Triage Stage: UnreviewedAccepted

comment:3 Changed 3 years ago by Guillaume Pannatier

Owner: changed from nobody to Guillaume Pannatier
Status: newassigned

comment:4 Changed 3 years ago by Guillaume Pannatier

PR available for review at:
https://github.com/django/django/pull/2704

Thanks

PS : I need help for change documentation
Because this new feature is assigned to version 1.6. I don't know how add
informations for this feature in docs/ref/forms/widgets.txt

comment:5 Changed 3 years ago by Guillaume Pannatier

Has patch: set

comment:6 Changed 3 years ago by Claude Paroz

Version: 1.6master

I left some comments on the PR. This will only be considered for 1.8, as 1.7 is already feature-frozen.

comment:7 Changed 3 years ago by Guillaume Pannatier

Thanks for your comments on the PR.
I made the necessary changes.

Last edited 3 years ago by Guillaume Pannatier (previous) (diff)

comment:8 Changed 3 years ago by Claude Paroz

Needs documentation: set

comment:9 Changed 3 years ago by Guillaume Pannatier

I have change the documentation with this new feature.

comment:10 Changed 3 years ago by Claude Paroz

@danielsamuels: does the proposed implementation fulfill your use case?

comment:11 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 32586b0ba43816d325be0ce807f75623683eed7a:

Fixed #22684 -- Added empty_label option on django.forms.extras.widets.SelectDateWidget

Thanks danielsamuels for the report

comment:12 Changed 3 years ago by Daniel Samuels

Apologies for the slow reply, seems as though being CC'd doesn't actually send emails. As far as I can see, this isn't providing the option to change the empty_label for each field individually. The widget provides 3 <select> fields, one for day, one for month and one for year, the pull request appears to be setting the empty value for all 3 at the same time. What I would like to be able to achieve is to have 'Day' as the default value for the Day dropdown, 'Month' as the default for the month dropdown and 'Year' as the default for the year dropdown. I'm not entirely sure what an appropriate default value could even be used with this pull request, as it would need to be relevant for all 3 dropdowns, which doesn't really seem very flexible.

My proposal would be to have 3 kwargs in place of the current 1, something along the lines of day_empty_label, month_empty_label and year_empty_label, this would give all of the flexibility required.

comment:13 Changed 3 years ago by Tim Graham

Resolution: fixed
Status: closednew

Or maybe change empty_label -> empty_labels and make it a 3-tuple corresponding to year/month/day?

comment:14 Changed 3 years ago by Guillaume Pannatier

For me, change the empty_label to empty_labels (3-tuple) seams to be a good idea.
What do you think @danielsamuels ?

comment:15 Changed 3 years ago by Guillaume Pannatier

We can also keep empty_label and accept a string or a 3-tuple ?
If a string is passed, all select will have the same empty_value otherwise, select will have corresponding values.

comment:16 Changed 3 years ago by Guillaume Pannatier

Status: newassigned

The new PR for review and remarks

https://github.com/django/django/pull/2737

comment:17 Changed 3 years ago by Daniel Samuels

That makes a lot more sense, thanks for putting the work in gyx1000.

comment:18 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 7e2c87809ca601b7290203dd54ba3e9f90a702bd:

Fixed #22684 -- Amended SelectDateWidget.empty_label to accept a tuple of values.

Thanks danielsamuels for the report

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