I'm trying to make a form that has radio buttons with different values
and descriptive text. For example, this:
<input type="radio" id="sex" value="xy" name="sex"/> male
<input type="radio" id="sex" value="xx" name="sex"/> female
instead of:
<input type="radio" id="sex" value="male" name="sex"/> male
<input type="radio" id="sex" value="female" name="sex"/> female
I'm trying to do so using web.form and the following code:
simple_form = form.Form(
form.Radio('sex',
[('xy', 'male'),('xx', 'female')],
description='Select your sex',
),
)
This code results in the following unexpected markup:
<input type="radio" id="sex" value="('xy',
'male')" name="sex"/> male
<input type="radio" id="sex" value="('xx',
'female')" name="sex"/> female
It looks like the description text is working as expected but instead
of using the first element of the tuple the whole tuple is being used
for the value attribute.
What am I doing incorrectly? Is it possible this is a bug? The
following patch (
http://pastebin.com/DJjHgds3) seems to make form.py
behave as I expected, but I know too little about the library to know
what other ramifications this may have:
--- form.py 2010-03-20 13:40:07.000000000 -0400
+++ form.py 2010-05-10 11:50:03.000000000 -0400
@@ -255,14 +255,15 @@
def render(self):
x = '<span>'
for arg in self.args:
+ attrs = self.attrs.copy()
if isinstance(arg, (tuple, list)):
value, desc= arg
+ attrs['value'] = arg[0]
else:
value, desc = arg, arg
- attrs = self.attrs.copy()
+ attrs['value'] = arg
attrs['name'] =
self.name
attrs['type'] = 'radio'
- attrs['value'] = arg
if self.value == arg:
attrs['checked'] = 'checked'
x += '<input %s/> %s' % (attrs, net.websafe(desc))
Thanks for the help.
--
You received this message because you are subscribed to the Google Groups "web.py" group.
To post to this group, send email to
we...@googlegroups.com.
To unsubscribe from this group, send email to
webpy+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/webpy?hl=en.