Opened 9 years ago

Closed 13 days ago

#5851 closed New feature (fixed)

SplitDateTimeWidget (or MultiWidget) doesn't allow different attrs for different fields

Reported by: ciantic@… Owned by: felixxm
Component: Forms Version: master
Severity: Normal Keywords: SplitDateTimeWidget MultiWidget
Cc: cmawebsite@…, kmike84@…, charette.s@…, james.kirsop@…, felisiak.mariusz@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Many times it is needed to have for instance different class attribute value for DateField than TimeField, therefore SplitDateTimeWidget should have a way to give different attrs for time and datefields.
(e.g. Javascript helpers, one with contrib.admin is good example)

There are two ways to fix the problem:
1.) add the possiblity to MultiWidget and let SplitDateTimeWidget merely use the ability or,
2.) add the possiblity to SplitDateTimeWidget

First method is semantically a bit more correct, but requires more than few seconds of implementation (Currently I'm out of time and I can't spare to implement patch for first approach).

Here is the patch for second approach (note that for the second approach leaving the multiwidget attrs as None was sufficient)

Attachments (2)

widgets_2.diff (727 bytes) - added by ciantic@… 9 years ago.
Second approach to the problem
5851.diff (4.7 KB) - added by Koen Biermans 5 years ago.
patch allow list of attrs into multiwidget

Download all attachments as: .zip

Change History (20)

Changed 9 years ago by ciantic@…

Attachment: widgets_2.diff added

Second approach to the problem

comment:1 Changed 9 years ago by anonymous

Component: Core frameworkdjango.newforms

comment:2 Changed 9 years ago by MichaelBishop

Triage Stage: UnreviewedDesign decision needed

Appears to be a design decision based on the options presented in the description.

If the first approach is chosen, then a patch is required. If the second approach is chosen, then the patch needs to be evaluated.

comment:3 Changed 9 years ago by Collin Anderson

Cc: cmawebsite@… added

Is this a duplicate of #4117?

comment:4 Changed 6 years ago by Gabriel Hurley

Severity: Normal
Type: New feature

comment:5 Changed 5 years ago by Jacob

Easy pickings: unset
Triage Stage: Design decision neededAccepted
UI/UX: unset

The first solution (making the fix to MultiWidget) is the right way to go.

comment:6 Changed 5 years ago by Julien Phalip

#14718 was closed as duplicate. See also #16754 for a related issue.

comment:7 Changed 5 years ago by Julien Phalip

#10343 was also closed as dupe.

comment:8 Changed 5 years ago by Jacob

And other: #16754.

comment:9 Changed 5 years ago by Mikhail Korobov

Cc: kmike84@… added
Needs tests: set
Patch needs improvement: set

Changed 5 years ago by Koen Biermans

Attachment: 5851.diff added

patch allow list of attrs into multiwidget

comment:10 Changed 5 years ago by Koen Biermans

Needs documentation: set
Needs tests: unset
Patch needs improvement: unset

Attaching a patch that allows passing a list of attrs into the multiwidget (first approach).

Includes some simple tests.

No documentation yet.

comment:11 Changed 4 years ago by Simon Charette

Cc: charette.s@… added

comment:12 Changed 6 months ago by James Kirsop

Cc: james.kirsop@… added

Would love to see this reviewed at some stage. It would be particularly helpful in supporting the "placeholder" attribute.

comment:13 Changed 6 months ago by Claude Paroz

Before this is reviewed, we should have a pull request with the proposed patch, including tests and docs.

comment:14 Changed 5 weeks ago by felixxm

Cc: felisiak.mariusz@… added
Needs documentation: unset
Owner: changed from nobody to felixxm
Status: newassigned

I think that this is a issue specific for SplitDateTimeWidget and SplitHiddenDateTimeWidget, because in general you can get the same result in a different way e.g.:

        Input(attrs={'class': 'foo'}),
        Input(attrs={'class': 'bar'}),

IMO there is no need to complicate MultiWidget.


comment:15 Changed 5 weeks ago by Tim Graham

Patch needs improvement: set

comment:16 Changed 5 weeks ago by felixxm

Patch needs improvement: unset

comment:17 Changed 2 weeks ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:18 Changed 13 days ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 0034e9a:

Fixed #5851 -- Allowed specifying different HTML attrs for SplitDateTimeWidget subwidgets.

Thanks Tim Graham and Nick Pope for review.

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