Django

Code

Ticket #4117 (assigned)

Opened 2 years ago

Last modified 3 months ago

Attributes for Widgets composed of more than one HTML element

Reported by: Iwan Vosloo Assigned to: Alex (accepted)
Milestone: post-1.0 Component: Forms
Version: SVN Keywords: attrs, RadioSelect, MultiWidget
Cc: gary.wilson@gmail.com, jaywgraves@gmail.com, cmawebsite@gmail.com Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

As suggested in #3870, I'm adding this ticket.

With widgets (such as {{RadioSelect?}} or {{MultiWidget?}}) that are rendered as several HTML elements/inputs one sometimes need a way to attach HTML attributes to the widget as a whole so that you can style its constituent parts using a stylesheet.

Please see the reason for this request in http://groups.google.com/group/django-developers/browse_thread/thread/e55be1c11893c069

A naïve implementation would be that if you construct the widget with attrs= keyword argument, they should be used as HTML attributes on a suitable element (as in #4080). It seems, however, as if the norm is as in #3870.

I believe a design decision is needed here: #4080 does one thing with attrs, #3870 does another thing with attrs. For general styling, I think #4080 is the way to go, but it appeared to me that #3870 makes sense in other cases. (For example if you want to set readonly attribute on the entire widget, it should be set on all inputs it is composed of).

-i

Attachments

4117.diff (1.7 kB) - added by Gary Wilson <gary.wilson@gmail.com> on 05/15/07 13:57:19.
attributes for containers of RadioSelect and CheckboxSelectMultiple widgets
widget-ul.diff (6.6 kB) - added by Alex on 06/19/08 12:57:50.
Here's an up to date patch, it adds the id attr, however it causes one test error(not failure), which is a UnicodeDecodeError?
widget-ul.2.diff (8.1 kB) - added by Alex on 06/19/08 13:50:38.
No more test failures
widget-ul-id.diff (8.3 kB) - added by Alex on 06/19/08 15:12:34.
This version only adds the id attr to the ul, there is a seperate ticket about making newforms more CSS friendsly so we can defer the rest of the attrs to that ticket.
widget-ul-id.2.diff (8.3 kB) - added by Alex on 08/08/08 11:09:22.
Same patch, just updated to apply against forms

Change History

04/28/07 17:21:55 changed by Simon G. <dev@simon.net.nz>

  • needs_better_patch changed.
  • stage changed from Unreviewed to Design decision needed.
  • needs_tests changed.
  • needs_docs changed.

05/15/07 13:13:14 changed by Gary Wilson <gary.wilson@gmail.com>

Please note that #4080 is a subset of what is asked for here and has a (slightly outdated) patch for fixing RadioSelect container attributes.

05/15/07 13:57:19 changed by Gary Wilson <gary.wilson@gmail.com>

  • attachment 4117.diff added.

attributes for containers of RadioSelect and CheckboxSelectMultiple widgets

05/15/07 13:59:38 changed by Gary Wilson <gary.wilson@gmail.com>

  • has_patch set to 1.
  • needs_tests set to 1.

MultiWidget doesn't have a containing element so there is nothing to do there. CheckboxSelectMultiple was the only other widget I noticed besides RadioSelect that used a container element.

05/15/07 17:35:04 changed by SmileyChris

  • needs_better_patch set to 1.

Gary, your patch sets the attributes on the lis as well as the containing ul for the RadioSelect but not the CheckboxSelectMultiple widget.

I'm not sure you need to set it on the lis, do you?

07/19/07 10:04:13 changed by anonymous

  • cc changed from gary.wilson@gmail.com to gary.wilson@gmail.com, jaywgraves@gmail.com.

07/19/07 21:06:22 changed by jaywgraves@gmail.com

for solving this for a RadioSelect? widget see #4228

06/19/08 12:57:50 changed by Alex

  • attachment widget-ul.diff added.

Here's an up to date patch, it adds the id attr, however it causes one test error(not failure), which is a UnicodeDecodeError?

06/19/08 13:50:38 changed by Alex

  • attachment widget-ul.2.diff added.

No more test failures

06/19/08 13:53:46 changed by Alex

  • owner changed from nobody to Alex.
  • needs_better_patch deleted.
  • status changed from new to assigned.
  • needs_tests deleted.

06/19/08 15:12:34 changed by Alex

  • attachment widget-ul-id.diff added.

This version only adds the id attr to the ul, there is a seperate ticket about making newforms more CSS friendsly so we can defer the rest of the attrs to that ticket.

07/07/08 14:53:29 changed by CollinAnderson

  • cc changed from gary.wilson@gmail.com, jaywgraves@gmail.com to gary.wilson@gmail.com, jaywgraves@gmail.com, cmawebsite@gmail.com.

Is #5851 a duplicate of this?

08/08/08 11:09:22 changed by Alex

  • attachment widget-ul-id.2.diff added.

Same patch, just updated to apply against forms

08/22/08 23:26:00 changed by Alex

  • milestone set to post-1.0.

It is with great regret that I say this will have to wait until after 1.0.


Add/Change #4117 (Attributes for Widgets composed of more than one HTML element)




Change Properties
Action