The patch I posted broke validation and would not work with radio buttons that had numbers as values this is the patch I should have attached (http://pastebin.com/VgBwpVWU): --- form.py 2010-03-20 13:40:07.000000000 -0400 +++ form_update.py 2010-05-10 13:05:30.000000000 -0400 @@ -262,8 +262,8 @@ attrs = self.attrs.copy() attrs['name'] = self.name attrs['type'] = 'radio' - attrs['value'] = arg - if self.value == arg: + attrs['value'] = value + if self.value == str(value): attrs['checked'] = 'checked' x += '<input %s/> %s' % (attrs, net.websafe(desc)) x += '</span>'
Question still stands: bug or user error? Thanks. Finn On May 10, 12:21 pm, FHSM <[email protected]> wrote: > 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/webpy?hl=en. -- You received this message because you are subscribed to the Google Groups "web.py" 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/webpy?hl=en.
