I have put together a custom form with checkboxes, based on the results of
a query.
This onvalidate function verifies that at least one checkbox is selected.
def post_validate(form):
for v in form.vars:
if v.startswith('add_') and form.vars[v]=='on':
return
form.errors['form'] = 'Nothing selected.'
The relevant part of the form handling looks like this:
if form.process(onvalidation=post_validate).accepted:
insert_records(form.vars)
elif form.errors:
response.flash = SPAN(
'Nothing selected; nothing to do.', _stye='color:red;'
)
This all works great except that the checkboxes come back with the checked
attribute set to "checked."
Here is the code that builds the checkboxes. Notice that I am setting a
boolean named checked to False. Somehow the checkbox widget is ignoring my
setting.
I will investigate this, but if someone has a clue now why this might be
happening I would appreciate knowing it.
Here's the code that makes the checkboxes, by the way.
rows = db().select(
db.auth_user.id, db.auth_user.name, orderby=db.auth_user.name)
if not len(rows): raise ValueError('No users available to assign.')
tbody = TBODY()
for r in rows:
checked = False
tbody.append(TR(
INPUT(_type='checkbox', _name='add_%s' %r.id, _checked=checked),
r.name
))
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.