Radio buttons and check boxes orientation

962 views
Skip to first unread message

Johann Spies

unread,
Jun 16, 2010, 9:22:57 AM6/16/10
to web...@googlegroups.com
How do I get radio buttons (and check boxes) to show up horizontally
in stead of vertically?

e.g.

Yes {} No {}

in stead of

Yes {}
No {}

Regards
Johann
--
"Finally, brethren, whatsoever things are true, whatsoever things are
honest, whatsoever things are just, whatsoever things are pure,
whatsoever things are lovely, whatsoever things are of good report; if
there be any virtue, and if there be any praise, think on these
things." Philippians 4:8

weheh

unread,
Jun 16, 2010, 10:44:03 AM6/16/10
to web2py-users
Find out the id or class of the radio buttons. Use firebug to see, or
look at the "CSS Conventions" section of the doc. You may need to
resort to a custom form, but I doubt it. Then set the css attribute:
display: inline; should probably do it. You may need to float the
first one ... not sure about that, though.

Johann Spies

unread,
Jun 16, 2010, 10:53:03 AM6/16/10
to web...@googlegroups.com
On 16 June 2010 16:44, weheh <richard...@verizon.net> wrote:
> Find out the id or class of the radio buttons. Use firebug to see, or
> look at the "CSS Conventions" section of the doc. You may need to
> resort to a custom form, but I doubt it. Then set the css attribute:
> display: inline; should probably do it. You may need to float the
> first one ... not sure about that, though.

Thanks. Firebug showed me that SQLForm is using a table to do it. I
will probably have to make a custom form.

weheh

unread,
Jun 16, 2010, 10:56:01 AM6/16/10
to web2py-users
I find myself mostly defaulting to custom forms for anything that an
end user sees. For internal app admin stuff, I am usually happy with
whatever web2py produces automatically.

On Jun 16, 10:53 am, Johann Spies <johann.sp...@gmail.com> wrote:

mr.freeze

unread,
Jun 16, 2010, 11:11:43 PM6/16/10
to web2py-users
Try this:
db.define_table('test',
Field('answer',default='Maybe'))
db.test.answer.requires = IS_IN_SET(['Yes','No','Maybe'])
def horizontal_radios(f,v):
table = SQLFORM.widgets.radio.widget(f,v)
rows = table.elements('tr')
table.components = []
table.append([row.elements('td') for row in rows])
return table
db.test.answer.widget = horizontal_radios

hywang

unread,
Jun 16, 2010, 11:38:00 PM6/16/10
to web2py-users
CheckboxesWidget can arrange check boxes horizontally.
you can specify the colum number by 'cols'

Try this:
db.define_table('test',
Field('children'))
db.test.children.requires =
IS_IN_SET(['boy1','girl1','boy2','girl2','boy3','girl3','boy4','girl4'])
def horizontal_checkbox(f,v):
return SQLFORM.widgets.checkboxes.widget(f,v, cols=2)

db.test.children.widget = horizontal_checkbox

chechboxes are shown in 4 rows and every row contains 2 columns.

Johann Spies

unread,
Jun 18, 2010, 8:03:52 AM6/18/10
to web...@googlegroups.com
Thanks MrFreeze and Hywang!
Reply all
Reply to author
Forward
0 new messages