Implementing HTML Select in Jinja

From PeformIQ Upgrade
Revision as of 10:37, 25 December 2014 by PeterHarding (talk | contribs) (Created page with "An example. <pre> {% macro states_select(name, value='', class='', id='') -%} {% set states = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL",...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

An example.

{% macro states_select(name, value='', class='', id='') -%}
 {% set states = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA",
"ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH",
"OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"] %}
 <select name="{{name}}" class="{{class}}" id="{{id}}">
 {% for state in states %}
 <option value="{{state}}" {{'selected' if value==state else ''}}>{{state}}</option>
 {% endfor %}
 </select>
{%- endmacro %}