在 web2py 中添加单选按钮到自定义表单
我正在尝试以自定义表单将字段显示为单选按钮组。我想将每个单选按钮放置在表格中的不同行上。问题是当我使用 {{=form.custom.selection_type[0]}}
时,小部件被包装在不需要的 tr
和 td
中标签。有没有办法只添加单选按钮?
我的表单:
{{extend 'layout.html'}}
{{=form.custom.begin}}
<table>
<tr>
<td> {{=form.custom.selection_type[0]}}:</td>
<td> {{=form.custom.widget.biller_list}}</td>
</tr>
<tr>
<td> {{=form.custom.widget.selection_type[1]}}:</td>
<td> {{=form.custom.widget.biller_code}}</td>
</tr>
</table>
{{=form.custom.end}}
html 源代码中发生的情况示例:
<table>
<tr>
<td> <tr><td><input name="selection_type" type="radio" value="From my biller list" />From my biller list</td></tr>:</td>
...
</tr>
...
</table>
我的模型:
db.define_table('payment_bpay_step1',
Field('selection_type', 'list:string'),
Field('biller_list', db.biller, notnull=True),
Field('biller_code'),
Field('biller_name'))
db.payment_bpay_step1.selection_type.requires = IS_IN_SET(('From my biller list', 'Search by biller code', 'Search by biller name'))
db.payment_bpay_step1.selection_type.widget = SQLFORM.widgets.radio.widget
I'm trying to display a field as a radio button group in a customised form. I want to place each radio button on a different row in a table. The problem is when I use {{=form.custom.selection_type[0]}}
, the widget is wrapped in unwanted tr
and td
tags. Is there a way to add only the radio button?
My form:
{{extend 'layout.html'}}
{{=form.custom.begin}}
<table>
<tr>
<td> {{=form.custom.selection_type[0]}}:</td>
<td> {{=form.custom.widget.biller_list}}</td>
</tr>
<tr>
<td> {{=form.custom.widget.selection_type[1]}}:</td>
<td> {{=form.custom.widget.biller_code}}</td>
</tr>
</table>
{{=form.custom.end}}
Example of what's happening in the html source code:
<table>
<tr>
<td> <tr><td><input name="selection_type" type="radio" value="From my biller list" />From my biller list</td></tr>:</td>
...
</tr>
...
</table>
My model:
db.define_table('payment_bpay_step1',
Field('selection_type', 'list:string'),
Field('biller_list', db.biller, notnull=True),
Field('biller_code'),
Field('biller_name'))
db.payment_bpay_step1.selection_type.requires = IS_IN_SET(('From my biller list', 'Search by biller code', 'Search by biller name'))
db.payment_bpay_step1.selection_type.widget = SQLFORM.widgets.radio.widget
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它尚未稳定,但在主干中,您现在可以为单选小部件指定 ul 或 divs 样式,而不是表格样式。我认为是:
您还可以创建一个自定义小部件,如 this 末尾所述书中的部分。
当您说您希望“innerhtml”与单选按钮的值不同时,您是在谈论单选按钮旁边的标签吗?为此,IS_IN_SET 验证器采用“labels”参数,它是与集合中的选项关联的标签列表。
It's not in stable yet, but in trunk, you can now specify ul or divs style rather than table style for the radio widget. I think it would be:
You can also create a custom widget, as described at the end of this section in the book.
When you say you want the "innerhtml" to be different from the value of the radio button, are you talking about the label next to the radio button? For that, the IS_IN_SET validator takes a 'labels' argument, which is a list of labels associated with the options in the set.