Difference between revisions of "Implementing HTML Select in Jinja"
Jump to navigation
Jump to search
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",...") |
PeterHarding (talk | contribs) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 13: | Line 13: | ||
{%- endmacro %} | {%- endmacro %} | ||
</pre> | </pre> | ||
=Also= | |||
http://stackoverflow.com/questions/20444285/how-do-i-populate-a-select-tag-with-flask | |||
<pre> | |||
<label>Select :</label> | |||
<select name="option" width="300px"> | |||
{% for option in ctx.select_option_list %} | |||
<option name="{{ option.id }}" {{'selected' if (option.value == ctx.select_value) else ''}}>{{ option.value }}</option> | |||
{% endfor %} | |||
</select> | |||
</pre> | |||
=Other Examples= | |||
<pre> | |||
<td class="label">Title:</td> | |||
<td> | |||
<select name="CHonorific" class="inputSelect"> | |||
{% for honorific in ctx.Honirific_options %} | |||
<option value="{{honorific}}" {{'selected' if ctx.CHonorific == honorific else ''}}>{{honorific}}</option> | |||
{% endfor %} | |||
</select> | |||
</td> | |||
<td> | |||
<select name="State" class="inputSelect"> | |||
{% for state in ctx.State_options %} | |||
<option value="{{state}}" {{'selected' if ctx.State == state else ''}}>{{state}}</option> | |||
{% endfor %} | |||
</select> | |||
</td> | |||
</pre> | |||
[[Category:Jinja]] | [[Category:Jinja]] | ||
[[Category:Flask]] | |||
[[Category:Python]] |
Latest revision as of 13:47, 26 June 2017
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 %}
Also
http://stackoverflow.com/questions/20444285/how-do-i-populate-a-select-tag-with-flask
<label>Select :</label> <select name="option" width="300px"> {% for option in ctx.select_option_list %} <option name="{{ option.id }}" {{'selected' if (option.value == ctx.select_value) else ''}}>{{ option.value }}</option> {% endfor %} </select>
Other Examples
<td class="label">Title:</td> <td> <select name="CHonorific" class="inputSelect"> {% for honorific in ctx.Honirific_options %} <option value="{{honorific}}" {{'selected' if ctx.CHonorific == honorific else ''}}>{{honorific}}</option> {% endfor %} </select> </td> <td> <select name="State" class="inputSelect"> {% for state in ctx.State_options %} <option value="{{state}}" {{'selected' if ctx.State == state else ''}}>{{state}}</option> {% endfor %} </select> </td>