Edgewall Software

Changes between Version 5 and Version 6 of GenshiRecipes/FormFilling


Ignore:
Timestamp:
Sep 24, 2006, 6:38:54 PM (18 years ago)
Author:
cmlenz
Comment:

Add match templates for select boxes

Legend:

Unmodified
Added
Removed
Modified
  • GenshiRecipes/FormFilling

    v5 v6  
    66#!xml
    77<html xmlns:py="http://genshi.edgewall.org/">
    8  
     8
    99  <input py:match="form//input[@type='text']" py:attrs="select('@*')"
    1010         value="${form.get(str(select('@name')))}" />
     
    1616  <textarea py:match="form//textarea" py:attrs="select('@*')"
    1717            py:content="form.get(str(select('@name')))"></textarea>
     18  <select py:match="form//select" py:attrs="select('@*')"
     19          py:with="select_name = str(select('@name'))"
     20          py:content="select('option|optgroup')" />
     21  <option py:match="form//select//option" py:attrs="select('@*')"
     22          py:with="sel_value = form.get(select_name)"
     23          selected="${sel_value and (str(select('@value')) == sel_value) or None}"
     24          py:content="select('@value')" />
    1825
    1926  <form action="" method="POST">
     
    3845      </label>
    3946    </fieldset>
     47    <!--! A select box -->
     48    <p>
     49      <label>Select another:
     50        <select name="dropdown">
     51          <option py:for="option in range(1, 4)" value="$option">$option</option>
     52        </select>
     53      </label>
     54    </p>
    4055  </form>
    4156</html>
     
    4964        'enable': '',
    5065        'option': 'B',
    51         'description': 'This is the description someone put in here'}
     66        'description': 'This is the description someone put in here',
     67        'dropdown': '2'}
    5268}}}
    5369
     
    8096      </label>
    8197    </fieldset>
     98    <p>
     99      <label>Select another:
     100        <select name="dropdown">
     101          <option value="1">1</option>
     102          <option selected="selected" value="2">2</option>
     103          <option value="3">3</option>
     104        </select>
     105      </label>
     106    </p>
    82107  </form>
    83108</html>
    84109}}}
    85110
    86 This recipe would need to be extended to also support select fields.
    87 
    88111----
    89112See also: GenshiRecipes, [wiki:Documentation/xml-templates.html Genshi XML Template Language]