Hi,
I am trying to get an image as a label in a RadioSelect... I have been
trying to get a grasp on using the RadioFieldRenderer() but I am
having no luck.
I currently have this in my widgets.py
from django.forms import widgets
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe
class BackgroundRadioRenderer(widgets.RadioFieldRenderer):
def render(self):
return mark_safe(u'\n'.join([u'<img src="%s">' % w for w in
self]))
I current have this in my forms.py
class ExampleForm(forms.Form):
CHOICES = (
(1,'thumb1.gif'),
(2,'thumb2.gif'),
(3,'thumb3.gif'),
(4,'thumb4.gif'),
)
background =
forms.ChoiceField(choices=CHOICES,widget=forms.RadioSelect(renderer=BackgroundRadioRenderer))
The output of this is:
<img src="<label for="id_background_0"><input type="radio"
id="id_background_0" value="1" name="background" /> thumb1.gif</
label>">
<img src="<label for="id_background_1"><input type="radio"
id="id_background_1" value="2" name="background" /> thumb2.gif</
label>">
<img src="<label for="id_background_2"><input type="radio"
id="id_background_2" value="3" name="background" /> thumb3.gif</
label>">
<img src="<label for="id_background_3"><input type="radio"
id="id_background_3" value="4" name="background" /> thumb4.gif</
label>">
How can I get the image to be the actual label itself?
Thanks
Jeff
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.