I took the silence as a sign and posted an issue on github. Hopefully the bug is in the code and note between my ears. Here's the link: http://github.com/webpy/webpy/issues#issue/13
Additionally, I separated out two separate issues with a second one covering forms with radio buttons or dropdowns that have the value attribute set to an integer. Because the posted form does not contain ints the test of equality in the form render fails. As a result the state of these elements is lost when redisplaying a form after an invalid submission attempt. I think this patch would fix the problem: 243c243 < if self.value == value: select_p = ' selected="selected"' --- > if self.value == str(value): select_p = ' selected="selected"' 266c266 < if self.value == arg: --- > if self.value == str(arg): This issue is here: http://github.com/webpy/webpy/issues#issue/14 Have I missed the correct use of the framework / implications of these changes or do they seem reasonable? On May 10, 8:08 pm, FHSM <[email protected]> wrote: > 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 > 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.
