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
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.