Opened 16 years ago

Closed 7 years ago

#5851 closed New feature (fixed)

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

Reported by: ciantic@… Owned by: Mariusz Felisiak
Component: Forms Version: dev
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

Description

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@… 16 years ago.
Second approach to the problem
5851.diff (4.7 KB ) - added by Koen Biermans 12 years ago.
patch allow list of attrs into multiwidget

Download all attachments as: .zip

Change History (20)

by ciantic@…, 16 years ago

Attachment: widgets_2.diff added

Second approach to the problem

comment:1 by anonymous, 16 years ago

Component: Core frameworkdjango.newforms

comment:2 by MichaelBishop, 16 years ago

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 by Collin Anderson, 16 years ago

Cc: cmawebsite@… added

Is this a duplicate of #4117?

comment:4 by Gabriel Hurley, 13 years ago

Severity: Normal
Type: New feature

comment:5 by Jacob, 13 years ago

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 by Julien Phalip, 13 years ago

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

comment:7 by Julien Phalip, 13 years ago

#10343 was also closed as dupe.

comment:8 by Jacob, 13 years ago

And other: #16754.

comment:9 by Mikhail Korobov, 13 years ago

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

by Koen Biermans, 12 years ago

Attachment: 5851.diff added

patch allow list of attrs into multiwidget

comment:10 by Koen Biermans, 12 years ago

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 by Simon Charette, 11 years ago

Cc: charette.s@… added

comment:12 by James Kirsop, 8 years ago

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 by Claude Paroz, 8 years ago

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

comment:14 by Mariusz Felisiak, 7 years ago

Cc: felisiak.mariusz@… added
Needs documentation: unset
Owner: changed from nobody to Mariusz Felisiak
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.:

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

IMO there is no need to complicate MultiWidget.

PR

comment:15 by Tim Graham, 7 years ago

Patch needs improvement: set

comment:16 by Mariusz Felisiak, 7 years ago

Patch needs improvement: unset

comment:17 by Tim Graham, 7 years ago

Triage Stage: AcceptedReady for checkin

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

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