web2py:单选按钮未在 SQLFORM 错误上呈现
我正在使用带有 SQLFORM 的自定义单选按钮,如下所示:
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)))
我用它来编辑表
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
这工作得很好,除非表单中存在错误 - 如果我对名称字段使用非唯一值,我会得到预期的结果错误消息,但单选按钮不再正确呈现 - 它们显示为:
[<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>]
我该如何解决这个问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过将生成的单选按钮包含在它们自己的 div 中来修复它:(
在返回中添加了 DIV)
I fixed it by enclosing the generated radio buttons in their own div:
(added the DIV in the return)