2

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
Anthony
  • 25,466
  • 3
  • 28
  • 57
br3nt
  • 9,017
  • 3
  • 42
  • 63

1 Answers1

1

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.

Anthony
  • 25,466
  • 3
  • 28
  • 57
  • Thanks! The labels argument of IS_IN_SET() worked well. I couldn't get the lamda function to work, though. I used your response in one of [your other answers](http://stackoverflow.com/questions/6596900/web2py-form-field-options) to create a custom widget instead. – br3nt Sep 18 '11 at 04:33
  • Note, the lambda function solution above will only work if you're using the current trunk version of web2py (not the current stable version, which is 1.98.2). Trunk will be released any day as 1.99.1. For now, you can get it [here](http://code.google.com/p/web2py/source/checkout). Or you can just copy the [new version of the widget](http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#286) to make a custom widget. – Anthony Sep 18 '11 at 06:40