Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 3 and Version 4 of CheckedCheckBox


Ignore:
Timestamp:
06/24/07 17:58:08 (11 years ago)
Author:
Chris Arndt
Comment:

migration notice

Legend:

Unmodified
Added
Removed
Modified
  • CheckedCheckBox

    v3 v4  
    1 = Automatically checking a checkbox or radio button = 
    2  
    3 The following: 
    4  
    51{{{ 
    6 #!text/html 
    7 <input type="checkbox" py:attrs="checked=std.checker(expression)" /> 
     2#!rst 
     3.. note:: This page has been migrated to http://docs.turbogears.org/1.0/CheckedCheckBox. 
    84}}} 
    9  
    10 will create a checked checkbox if the expression is true. 
    11  
    12 == Dynamic checkboxes == 
    13  
    14 To create a dynamic list of checkboxes (or radio buttons), with the appropriate ones pre-checked: 
    15  
    16 {{{ 
    17 #!python 
    18 from model import YourDataType 
    19  
    20 class YourController: 
    21     @turbogears.expose(...) 
    22     def index(self): 
    23         items = YourDataType.select() 
    24         # Select some examples items; in reality, these would be pulled from another SQLObject or other source 
    25         items_selected = [4, 5, 9] 
    26         return dict(items = items, items_selected = items_selected) 
    27 }}} 
    28  
    29 Then in the template: 
    30  
    31 {{{ 
    32 #!text/html 
    33 <!-- Using py:strip below means that the div will not be in the resulting HTML; we're just using it as a wrapper --> 
    34 <div py:for="i in items" py:strip="True"> 
    35   <label><input type="checkbox" name="selecteditems" value="${i.id}" py:attrs="checked=std.checker(i.id in items_selected)"/>${i.label}</label> 
    36 </div> 
    37 }}}