License Public Domain
Lines 5
Keywords
form (1) FormEncode (1) html (6) radio button (1) ToscaWidgets (1)
Permissions
Viewable by Everyone
Editable by All Siafoo Users
Hide
Siafoo is here to make coding less frustrating and to save you time. Join Siafoo Now or Learn More

Easy Radio Buttons in Toscawidgets Atom Feed 0

In Brief A quick example of how to use radio buttons in toscawidgets. Make sure you don't forget the Int validator, or NOTHING will work and you'll evaluate to True no matter what.... more
# 's
1from tw.forms.fields import RadioButtonList
2from tw.api import WidgetsList
3
4class SomeFormFields(WidgetsList):
5
6 do_you_like_siafoo = RadioButtonList(options=[[1,'Yes'], [0,'No, I love it']], validator=Int)
7

A quick example of how to use radio buttons in toscawidgets. Make sure you don't forget the Int validator, or NOTHING will work and you'll evaluate to True no matter what.

Pass RadioButtonList an array of [value, description, any_extra_args] arrays, and you'll end up with nice radio buttons, in the order you ask for them. The result of course is:

# 's
1<ul id="form_do_you_like_siafoo" class="radiobuttonlist">
2 <li>
3 <input type="radio" checked="checked" value="1" id="form_do_you_like_siafoo_0" name="do_you_like_siafoo">
4 <label for="form_do_you_like_siafoo_0">Yes</label>
5 </li><li>
6 <input type="radio" value="0" id="form_do_you_like_siafoo_1" name="do_you_like_siafoo">
7 <label for="form_do_you_like_siafoo_1">No, I love it</label>
8 </li>
9</ul>

Which is just what we want. Don't know why this isn't documented anywhere.