在 web2py 中添加单选按钮到自定义表单

发布于 2024-12-05 11:49:10 字数 1340 浏览 0 评论 0原文

我正在尝试以自定义表单将字段显示为单选按钮组。我想将每个单选按钮放置在表格中的不同行上。问题是当我使用 {{=form.custom.selection_type[0]}} 时,小部件被包装在不需要的 trtd 中标签。有没有办法只添加单选按钮?

我的表单:

{{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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泛泛之交 2024-12-12 11:49:10

它尚未稳定,但在主干中,您现在可以为单选小部件指定 ul 或 divs 样式,而不是表格样式。我认为是:

db.payment_bpay_step1.selection_type.widget = \
    lambda f, v: SQLFORM.widgets.radio.widget(f, v, style='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:

db.payment_bpay_step1.selection_type.widget = \
    lambda f, v: SQLFORM.widgets.radio.widget(f, v, style='divs')

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文