On Fri, 2008-11-14 at 06:25 -0800, Bobby Roberts wrote:
> hi.  I have the following code in my forms.py
> 
> 
> Anonymous = forms.ChoiceField (choices=Anonymous_Choices,
> widget=forms.RadioSelect(attrs={'class':'anonymous'}))
> 
> 
> which sets up a radio button UL on my form.  This part is working
> great.  however, i've got a problem.
> 
> 
> When viewing the source below:
> 
> 
> <td class="formright"><ul>
> <li><label><input value="Y" type="radio" class="anonymous"
> name="Anonymous" id="id_Anonymous_0" /> Yes</label></li>
> <li><label><input value="N" type="radio" class="anonymous"
> name="Anonymous" id="id_Anonymous_1" /> No</label></li>
> </ul>&nbsp;(Check for yes)</td>
> 
> 
> You can see the class is added to the LI element, not the UL.  How do
> i stick a class on the UL itself so I can format that list?  I have
> several like this on my form and they each need to be edited
> independently in regard to their style.

This is one of those cases where looking at the source for the widget in
question would be a good way to answer the question. The code isn't that
hard to understand -- it's a couple of self-contained classes in
django/forms/widgets.py.

If you have a look, you'll see that the individual items for the
RadioSelect widget are rendered by another class (RadioFieldRenderer),
which calls a third class (!), RadioChoice. The RadioChoice produces the
ultimate HTML line and doesn't use anything from attrs except the "id"
attribute. Part of the reason for this is no doubt because the data
structures get a little messy when they need to differentiate between
things for the main widget and things for the subitem. Since we want to
allow a dictionary to be passed in, simplicity wins out.

So you need to set the renderer attribute on RadioSelect to pass in a
subclass of RadioFieldRenderer that calls a class (that you create)
which does use your attributes on the individual line items, if you want
to go that way.

I'll also note that you may well be able to avoid all of this just by
adjusting your CSS rules (or Javascript selectors). Having the class on
the ul element means you can write ".ul li" to access the contained list
elements. That's the more traditional way to work with this element.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to