2
我试图在自定义窗体中显示一个字段作为单选按钮组。我想将每个单选按钮放在表格的不同行中。问题是当我使用{{=form.custom.selection_type[0]}}
时,小部件被封装在不需要的tr
和td
标签中。有没有办法只添加单选按钮?在web2py中添加单选按钮到自定义窗体
我的方式:发生了什么事在HTML源代码的
{{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}}
例子:
<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
谢谢! IS_IN_SET()的标签参数运行良好。不过,我无法让lamda功能起作用。我在[你的其他答案](http://stackoverflow.com/questions/6596900/web2py-form-field-options)之一中使用了你的响应来创建一个自定义小部件。 – br3nt
请注意,上面的lambda函数解决方案仅适用于使用web2py的当前中继版本(不是当前稳定版本,即1.98.2)的情况。 Trunk将在1.99.1的任何一天发布。目前,您可以在[这里]找到它(http://code.google.com/p/web2py/source/checkout)。或者,您可以复制[新版本的小部件](http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#286)以制作自定义小部件。 – Anthony