Discussion:
Change render of RadioSelect
Michael Irani
2008-05-05 06:46:23 UTC
Permalink
Hello,
I'm trying to manipulate the rendering for RadioSelect so that the
form element shows up within my form differently than a <UL>. So far
I've come across two options... Use straight form tags in my view, or
to rework RadioFieldRenderer and RadioInput from widgets.py locally so
that I can have a custom renderer. And then use that custom renderer
as the renderer for RadioSelect

I was wondering if there was a way to bipass these options and just
get at the independant radio buttons that make up the RadioSelect.
Meaning to be able to get all the 2-tuple key-value pairs that makeup
the RadioSelect widget.

Thanks,
Mike.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Karen Tracey
2008-05-05 12:06:29 UTC
Permalink
Post by Michael Irani
Hello,
I'm trying to manipulate the rendering for RadioSelect so that the
form element shows up within my form differently than a <UL>. So far
I've come across two options... Use straight form tags in my view, or
to rework RadioFieldRenderer and RadioInput from widgets.py locally so
that I can have a custom renderer. And then use that custom renderer
as the renderer for RadioSelect
I was wondering if there was a way to bipass these options and just
get at the independant radio buttons that make up the RadioSelect.
Meaning to be able to get all the 2-tuple key-value pairs that makeup
the RadioSelect widget.
RadioSelect allows for you to provide a custom rendering object. See:

http://code.djangoproject.com/ticket/4228

Does that not let you do what you want without changing your Django source
locally?

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Michael Irani
2008-05-05 18:02:11 UTC
Permalink
Karen,
That patch is actually kind of beautiful. Just in case someone else is
looking at this as of the current codebase the custom renderer would
like like this:
class MyRenderer(RadioFieldRenderer):
def render(self):
return mark_safe(u'\n%s\n' % u'\n'.join([u'%s' % w for w in
self]))

class SearchForm(forms.Form):
shape =
forms.ChoiceField(widget=forms.RadioSelect(renderer=MyRenderer))

I'd still rather have access to each of the items within the template
though. I'm trying to match up each of the radio buttons with an
image, and it'd be easier to handle within the template.

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

Loading...