Re: Checkboxes
"A Monkey" <[email protected]>
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
On Jan 29, 2008 10:37 PM, Mike Orr <[email protected]> wrote: > > Well, my real value is a Python boolean from SQLAlchemy.. My HTML has > value="1". htmlfill changes the value to 'yes'. I'm usin g the > StringBoolean validator. > > Originally I called it as: > > rslt = htmlfill.render(html, {'mycheckbox': record.field}) > > I had better luck when I changed it to: > > rslt = htmlfill.render(html, {'mycheckbox': > record.field and "1" or ""}) > > But I'm still testing it. I think I also pre-set the > initially-checked state, though I'd have to check that tomorrow. > > But I wish htmlfill would set the checkbox based on the boolean value, > which seems like the most pythonic way to do it. > > I can try it without a value attribute and see if that works better. > But then it won't be compatible with WebHelpers, which defaults to > value='1'. I think that htmlfill does the most reasonable thing given the situation. The value attribute is required for inputs of type checkbox, and so htmlfill checks the checkboxes with the given name _and the given value_. I'm guessing that you're using htmlfill here to pre-populate your form. If you're going to do that, I think that something along the lines of your second attempt is the way to go. I don't use htmlfill to pre-populate my forms, and I'd recommend against it to anyone that asked. I use my templating language. htmlfill is super-useful for redrawing forms after failed validation, but it always felt like it was more work to use htmlfill to pre-populate than it was worth. ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/