Opened 9 months ago

Closed 9 months ago

#22684 closed New feature (fixed)

SelectDateWidget's none_value is not changeable

Reported by: danielsamuels Owned by: gyx1000
Component: Forms Version: master
Severity: Normal Keywords:
Cc: danielsamuels 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 9 months ago by danielsamuels

  • Cc danielsamuels added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 9 months ago by claudep

  • Easy pickings set
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 9 months ago by gyx1000

  • Owner changed from nobody to gyx1000
  • Status changed from new to assigned

comment:4 Changed 9 months ago by gyx1000

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 9 months ago by gyx1000

  • Has patch set

comment:6 Changed 9 months ago by claudep

  • Version changed from 1.6 to master

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 9 months ago by gyx1000

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

Last edited 9 months ago by gyx1000 (previous) (diff)

comment:8 Changed 9 months ago by claudep

  • Needs documentation set

comment:9 Changed 9 months ago by gyx1000

I have change the documentation with this new feature.

comment:10 Changed 9 months ago by claudep

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

comment:11 Changed 9 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 32586b0ba43816d325be0ce807f75623683eed7a:

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

Thanks danielsamuels for the report

comment:12 Changed 9 months ago by danielsamuels

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 9 months ago by timo

  • Resolution fixed deleted
  • Status changed from closed to new

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

comment:14 Changed 9 months ago by gyx1000

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 9 months ago by gyx1000

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 9 months ago by gyx1000

  • Status changed from new to assigned

The new PR for review and remarks

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

comment:17 Changed 9 months ago by danielsamuels

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

comment:18 Changed 9 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

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