HOWTO: usar DIV en radiobuttons generados en lugar de TABLE

web2py: Use divs in generated radiobutton instead of table – Stack Overflow

 

I have a table:

db.define_table('table1',
    Field('name', 'string', length=16, required=True, unique=True),
    Field('shape', 'string', length=12, default='star', widget=SQLFORM.widgets.radio.widget, requires=IS_IN_SET(shapes)))

I use this SQLFORM to generate the form:

form = SQLFORM(db.table1, formstyle='divs')

I have the main form using divs, but the radio buttons, still use tables, which is really the one I want in divs. How can can I fix this?

link|improve this question


 
   
feedback

1 Answer

up vote 1 down vote accepted

I think you’ll have to create a custom widget (see http://web2py.com/book/default/chapter/07#Widgets). For example:

def div_radio_widget(field, value, **attributes):
    table=SQLFORM.widgets.radio.widget(field, value, **attributes)
    return DIV(
        *[SPAN(td.element('input'), LABEL(td.components[1]))
          for td in table.elements('td')],
        **table.attributes)

The above widget first creates a table using the built-in radio button widget and then pulls out the input elements and labels from the TD’s and puts everything in a DIV.

In your table definition, just replace:

widget=SQLFORM.widget.radio.widget

with:

widget=div_radio_widget
link|improve this answer

 

0

0
 

Leave a Reply