comparison sat_templates/templates/bulma/input/field.html @ 269:edefc1f25219

bulma (input/field): fixed use of `attrs` in `field`, added args, replaced use of `kwargs`
author Goffi <goffi@goffi.org>
date Fri, 14 Aug 2020 08:34:07 +0200
parents a18374320194
children fbea1b9a558f
comparison
equal deleted inserted replaced
268:ce2fd7a3911d 269:edefc1f25219
9 {% set cur_id = name|next_gidx %} 9 {% set cur_id = name|next_gidx %}
10 {% if label %} 10 {% if label %}
11 <label for="{{cur_id}}" class="label">{{label}}</label> 11 <label for="{{cur_id}}" class="label">{{label}}</label>
12 {% endif %} 12 {% endif %}
13 <div class="control{% if icon_left %} has-icons-left{% endif %}{% if icon_right %} has-icons-right{% endif %}"> 13 <div class="control{% if icon_left %} has-icons-left{% endif %}{% if icon_right %} has-icons-right{% endif %}">
14 <input id="{{cur_id}}" class="input" type="{{type}}" name="{{name}}" {{"required" if required}}{{{'value': value}|xmlattr}}{{attrs or {}|xmlattr}}> 14 <input id="{{cur_id}}" class="input" type="{{type}}" name="{{name}}" {{"required" if required}}{{{'value': value}|xmlattr}}{{(attrs or {})|xmlattr}}>
15 {% if icon_left %} 15 {% if icon_left %}
16 <span class="icon is-left"> 16 <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 #} 17 {# 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> 18 <i class="icon-{{icon_left}}"></i>
19 </span> 19 </span>
28 <p class="help">{{help}}</p> 28 <p class="help">{{help}}</p>
29 {% endif %} 29 {% endif %}
30 </div> 30 </div>
31 {% endmacro %} 31 {% endmacro %}
32 32
33 {% macro select(name, options_list, selected=none, required=false, multiple=false) %} 33 {% macro select(name, options_list, selected=none, required=false, multiple=false, class='') %}
34 {# selection of elements with <select> 34 {# selection of elements with <select>
35 35
36 @param name: name of the field 36 @param name: name of the field
37 @param options_list(list[str, str]): list of name, label of options 37 @param options_list(list[str, str]): list of name, label of options
38 @param selected(none, list): list of select elements 38 @param selected(none, list): list of select elements
39 @param required(bool): true this field is required 39 @param required(bool): true this field is required
40 @param multiple(bool): true is multiple selection is possible 40 @param multiple(bool): true is multiple selection is possible
41 #} 41 #}
42 <select name="{{name}}" class="form_input {{kwargs.pop('class', '')}}" {{"required" if required}}> 42 <select name="{{name}}" class="form_input {{class}}" {{"required" if required}}>
43 {% for value, label in options_list %} 43 {% for value, label in options_list %}
44 <option value="{{value}}" {{'selected' if selected and value in selected}}>{{label}}</option> 44 <option value="{{value}}" {{'selected' if selected and value in selected}}>{{label}}</option>
45 {% endfor %} 45 {% endfor %}
46 </select> 46 </select>
47 {% endmacro %} 47 {% endmacro %}
48 48
49 {% macro choices(name, choices_list, checked=none) %} 49 {% macro choices(name, choices_list, checked=none, class='') %}
50 <div class="control {{kwargs.pop('class', '')}}"> 50 <div class="control {{class}}">
51 {% for choice, label in choices_list %} 51 {% for choice, label in choices_list %}
52 <label class="radio" for="{{name|cur_gidx}}"> 52 <label class="radio" for="{{name|cur_gidx}}">
53 <input id="{{name|next_gidx}}" type="radio" name="{{name}}" value="{{choice}}"{{" checked" if checked==choice}}> {{label}} 53 <input id="{{name|next_gidx}}" type="radio" name="{{name}}" value="{{choice}}"{{" checked" if checked==choice}}> {{label}}
54 </label> 54 </label>
55 {% endfor %} 55 {% endfor %}
64 {% set cur_id = name|next_gidx %} 64 {% set cur_id = name|next_gidx %}
65 <label for="{{cur_id}}" class="label checkbox">{{label}}</label> 65 <label for="{{cur_id}}" class="label checkbox">{{label}}</label>
66 <input id="{{cur_id}}" type="checkbox" {% if checked %}checked=checked{% endif %}> 66 <input id="{{cur_id}}" type="checkbox" {% if checked %}checked=checked{% endif %}>
67 {% endmacro %} 67 {% endmacro %}
68 68
69 {% macro text(name, label="", value=none, class='', placeholder=none, required=false, icon_left=none, icon_right=none) %} 69 {% macro text(name, label="", value=none, class='', placeholder=none, required=false, pattern=none, title=none, autocomplete=none, icon_left=none, icon_right=none) %}
70 {{ field("text", name=name, label=label, value=value, class=class, required=required, icon_left=icon_left, icon_right=icon_right, attrs={'placeholder': placeholder}) }} 70 {{ field("text", name=name, label=label, value=value, class=class, required=required, icon_left=icon_left, icon_right=icon_right, attrs={'placeholder': placeholder, 'pattern': pattern, 'title': title, 'autocomplete': autocomplete}) }}
71 {% endmacro %} 71 {% endmacro %}
72 72
73 {% macro password(name, label="", required=false, icon_left=none, icon_right=none) %} 73 {% macro password(name, label="", value=none, required=false, minlength=none, icon_left=none, icon_right=none) %}
74 {{ field("password", name=name, label=label, required=required, icon_left=icon_left, icon_right=icon_right) }} 74 {{ field("password", name=name, label=label, value=value, required=required, icon_left=icon_left, icon_right=icon_right, attrs={'minlength': minlength}) }}
75 {% endmacro %} 75 {% endmacro %}
76 76
77 {% macro email(name, label="", required=false) %} 77 {% macro email(name, label="", required=false, value=none, icon_left=none, icon_right=none) %}
78 {{ field("email", name=name, label=label, required=required) }} 78 {{ field("email", name=name, label=label, value=value, required=required, icon_left=icon_left, icon_right=icon_right) }}
79 {% endmacro %} 79 {% endmacro %}
80 80
81 {% macro date(name, label="", required=false) %} 81 {% macro date(name, label="", required=false) %}
82 {{ field("date", name=name, label=label, required=required) }} 82 {{ field("date", name=name, label=label, required=required) }}
83 {% endmacro %} 83 {% endmacro %}
105 105
106 {% macro meta(name, value) %} 106 {% macro meta(name, value) %}
107 <input type="hidden" name="{{name}}" value="{{value}}"> 107 <input type="hidden" name="{{name}}" value="{{value}}">
108 {% endmacro %} 108 {% endmacro %}
109 109
110 {% macro submit(text=_("Send"), id=none, class='') %} 110 {% macro submit(text=_("Send"), id=none, class='', attrs=none) %}
111 {# submit button 111 {# submit button
112 112
113 @param text(str): label of the button 113 @param text(str): label of the button
114 @param id(none, str): id of the element 114 @param id(none, str): id of the element
115 #} 115 #}
116 <div class="control {{class}}"> 116 <div class="control {{class}}">
117 <button{{ {'id': id}|xmlattr }} class="button is-primary form_submit {{kwargs.pop('class', '')}}" type="submit">{{text}}</button> 117 <button{{ {'id': id}|xmlattr }} class="button is-primary form_submit {{class}}" type="submit"{{(attrs or {})|xmlattr}}>{{text}}</button>
118 </div> 118 </div>
119 {% endmacro %} 119 {% endmacro %}