I’m using custom radiobuttons with a SQLFORM as shown below:
def radioboxes(field,value):
items=[DIV(name,INPUT(_type='radio',_value=key,_name=field.name,value=value), _class='radio')
for key,name in field.requires.options() if key]
return items
db.define_table('table1',
Field('name', 'string', length=16, required=True, unique=True, ),
Field('shape', 'string', length=12, default='star', widget=radioboxes, requires=IS_IN_SET(shapes)))
I use this to edit the table
record = db.table1(session.table1_id)
form = SQLFORM(db.table1, record, fields=['name', 'shape'], showid=False, deletable=True, delete_label='Delete', col3=col3) # edit/delete
This works perfectly, except when there’s an error in the form – if I use a non-unique value for the name field, I get the expected error message, but the radio-buttons are not rendered correctly anymore – they show up as:
[<gluon.html.DIV object at 0x08C9F850>, <gluon.html.DIV object at 0x08C9F130>, <gluon.html.DIV object at 0x08C9FFD0>, <gluon.html.DIV object at 0x08C9F070>, <gluon.html.DIV object at 0x08C9FD10>, <gluon.html.DIV object at 0x08C9F8F0>, <gluon.html.DIV object at 0x08C9FE10>, <gluon.html.DIV object at 0x08C9FF90>, <gluon.html.DIV object at 0x08C9FE90>, <gluon.html.DIV object at 0x08C9F6B0>, <gluon.html.DIV object at 0x08C9F610>]
How can I fix this?
I fixed it by enclosing the generated radio buttons in their own div:
(added the DIV in the return)