comparison sat_templates/templates/bulma/input/field.html @ 304:cdf88211b86b

bulma (input/field): `field` macro now has `control_class` and `in_group` attributes: - `control_class` is used to specify additional classes for the control (when `class` is used for classes of the of the `field`) - when `in_group` is `true`, `field` is not added, only the `control` is used. This is useful for grouping elements in the same field
author Goffi <goffi@goffi.org>
date Sat, 27 Feb 2021 20:44:01 +0100
parents fbea1b9a558f
children 552daa830d42
comparison
equal deleted inserted replaced
303:877f01720036 304:cdf88211b86b
1 {# macros to create form fields #} 1 {# macros to create form fields #}
2 2
3 {% macro field(type, name, label="", value=none, class='', help="", required=false, icon_left=none, icon_right=none, attrs=none) %} 3 {% macro field(type, name, label="", value=none, class="", control_class="", help="", required=false, icon_left=none, icon_right=none, in_group=false, attrs=none) %}
4 {# generic field 4 {# generic field
5 "class" keyword can be used to add classes 5 "class" keyword can be used to add classes
6 additional kwargs will be passed as attributes #} 6 additional kwargs will be passed as attributes #}
7 7
8 <div class="field form_input {{class}}"> 8 {% if not in_group %}
9 <div class="field form_input {{class}}">
10 {% endif %}
9 {% set cur_id = name|next_gidx %} 11 {% set cur_id = name|next_gidx %}
10 {% if label %} 12 {% if label %}
11 <label for="{{cur_id}}" class="label">{{label}}</label> 13 <label for="{{cur_id}}" class="label">{{label}}</label>
12 {% endif %} 14 {% endif %}
13 <div class="control{% if icon_left %} has-icons-left{% endif %}{% if icon_right %} has-icons-right{% endif %}"> 15 <div class="control{% if icon_left %} has-icons-left{% endif %}{% if icon_right %} has-icons-right{% endif %} {{control_class}}">
14 <input id="{{cur_id}}" class="input" type="{{type}}" name="{{name}}" {{"required" if required}}{{{'value': value}|xmlattr}}{{(attrs or {})|xmlattr}}> 16 <input id="{{cur_id}}" class="input" type="{{type}}" name="{{name}}" {{"required" if required}}{{{'value': value}|xmlattr}}{{(attrs or {})|xmlattr}}>
15 {% if icon_left %} 17 {% if icon_left %}
16 <span class="icon is-left"> 18 <span class="icon is-left">
17 {# we use <i> with font from CSS instead of SVG, because using directly SVG doesn't play way with Bulma's control #} 19 {# we use <i> with font from CSS instead of SVG, because using directly SVG doesn't play way with Bulma's control #}
18 <i class="icon-{{icon_left}}"></i> 20 <i class="icon-{{icon_left}}"></i>
28 <p class="help">{{help}}</p> 30 <p class="help">{{help}}</p>
29 {% endif %} 31 {% endif %}
30 {% if caller %} 32 {% if caller %}
31 {{ caller() }} 33 {{ caller() }}
32 {% endif %} 34 {% endif %}
33 </div> 35 {% if not in_group %}
36 </div>
37 {% endif %}
34 {% endmacro %} 38 {% endmacro %}
35 39
36 {% macro select(name, options_list, selected=none, required=false, multiple=false, class='') %} 40 {% macro select(name, options_list, selected=none, required=false, multiple=false, class="") %}
37 {# selection of elements with <select> 41 {# selection of elements with <select>
38 42
39 @param name: name of the field 43 @param name: name of the field
40 @param options_list(list[str, str]): list of name, label of options 44 @param options_list(list[str, str]): list of name, label of options
41 @param selected(none, list): list of select elements 45 @param selected(none, list): list of select elements
47 <option value="{{value}}" {{'selected' if selected and value in selected}}>{{label}}</option> 51 <option value="{{value}}" {{'selected' if selected and value in selected}}>{{label}}</option>
48 {% endfor %} 52 {% endfor %}
49 </select> 53 </select>
50 {% endmacro %} 54 {% endmacro %}
51 55
52 {% macro choices(name, choices_list, checked=none, class='') %} 56 {% macro choices(name, choices_list, checked=none, class="") %}
53 <div class="control {{class}}"> 57 <div class="control {{class}}">
54 {% for choice, label in choices_list %} 58 {% for choice, label in choices_list %}
55 <label class="radio" for="{{name|cur_gidx}}"> 59 <label class="radio" for="{{name|cur_gidx}}">
56 <input id="{{name|next_gidx}}" type="radio" name="{{name}}" value="{{choice}}"{{" checked" if checked==choice}}> {{label}} 60 <input id="{{name|next_gidx}}" type="radio" name="{{name}}" value="{{choice}}"{{" checked" if checked==choice}}> {{label}}
57 </label> 61 </label>
91 95
92 {% macro file(name, label="", required=false) %} 96 {% macro file(name, label="", required=false) %}
93 {{ field("file", name=name, label=label, required=required) }} 97 {{ field("file", name=name, label=label, required=required) }}
94 {% endmacro %} 98 {% endmacro %}
95 99
96 {% macro textarea(name, label="", rows=none, cols=50, placeholder='', help='', required=false) %} 100 {% macro textarea(name, label="", rows=none, cols=50, placeholder="", help="", required=false) %}
97 <div class="field form_input"> 101 <div class="field form_input">
98 {% set cur_id = name|next_gidx %} 102 {% set cur_id = name|next_gidx %}
99 {% if label %} 103 {% if label %}
100 <label for="{{cur_id}}" class="label">{{label}}</label> 104 <label for="{{cur_id}}" class="label">{{label}}</label>
101 {% endif %} 105 {% endif %}