comparison sat_templates/templates/default/input/field.html @ 203:bdc578994b97

input/field: added "select" field for <select> inputs + "id" attribute can now be specified for submit button
author Goffi <goffi@goffi.org>
date Sun, 26 May 2019 22:06:10 +0200
parents 178f55b825b7
children aa37750c2617
comparison
equal deleted inserted replaced
202:a1fa6744c78e 203:bdc578994b97
9 {% if label %} 9 {% if label %}
10 <label for="{{cur_id}}" {{'class="required"'|safe if required}}>{{label}}</label> 10 <label for="{{cur_id}}" {{'class="required"'|safe if required}}>{{label}}</label>
11 {% endif %} 11 {% endif %}
12 <input id="{{cur_id}}" type="{{type}}" name="{{name}}" {{"required" if required}} {{kwargs|xmlattr}}> 12 <input id="{{cur_id}}" type="{{type}}" name="{{name}}" {{"required" if required}} {{kwargs|xmlattr}}>
13 </span> 13 </span>
14 {% endmacro %}
15
16 {% macro select(name, options_list, selected=none, required=false, multiple=false) %}
17 {# selection of elements with <select>
18
19 @param name: name of the field
20 @param options_list(list[str, str]): list of name, label of options
21 @param selected(none, list): list of select elements
22 @param required(bool): true this field is required
23 @param multiple(bool): true is multiple selection is possible
24 #}
25 <select name="{{name}}" class="form_input {{kwargs.pop('class', '')}}" {{"required" if required}}>
26 {% for value, label in options_list %}
27 <option value="{{value}}" {{'selected' if selected and value in selected}}>{{label}}</option>
28 {% endfor %}
29 </select>
14 {% endmacro %} 30 {% endmacro %}
15 31
16 {% macro choices(name, choices_list, checked=none) %} 32 {% macro choices(name, choices_list, checked=none) %}
17 {% for choice, label in choices_list %} 33 {% for choice, label in choices_list %}
18 <div class="form_input {{kwargs.pop('class', '')}}"> 34 <div class="form_input {{kwargs.pop('class', '')}}">
69 85
70 {% macro meta(name, value) %} 86 {% macro meta(name, value) %}
71 <input type="hidden" name="{{name}}" value="{{value}}"> 87 <input type="hidden" name="{{name}}" value="{{value}}">
72 {% endmacro %} 88 {% endmacro %}
73 89
74 {% macro submit(text=_("Send")) %} 90 {% macro submit(text=_("Send"), id=none) %}
75 <input class="form_submit btn" type="submit" value="{{text}}" class="{{kwargs.pop('class', '')}}"> 91 {# submit button
92
93 @param text(str): label of the button
94 @param id(none, str): id of the element
95 #}
96 <input {{ 'id="{id}"'.format(id=id)|safe if id }} class="form_submit btn" type="submit" value="{{text}}" class="{{kwargs.pop('class', '')}}">
76 {% endmacro %} 97 {% endmacro %}