comparison sat_templates/templates/bulma/input/field.html @ 249:60bf3e45d7b2

bulma (input/field): don't use kwargs anymore: `**kwargs` syntax is not supported by `nunjucks`. To work around this, most important arguments have been added directly to macros, and an extra `attrs` argument can be used for others.
author Goffi <goffi@goffi.org>
date Thu, 16 Jul 2020 09:08:34 +0200
parents 0e69b5843c2f
children a18374320194
comparison
equal deleted inserted replaced
248:a841837afe78 249:60bf3e45d7b2
1 {# macros to create form fields #} 1 {# macros to create form fields #}
2 2
3 {% macro field(type, name, label="", help="", required=false, icon_left=none, icon_right=none) %} 3 {% macro field(type, name, label="", value=none, class='', help="", required=false, icon_left=none, icon_right=none, 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 {{kwargs.pop('class', '')}}"> 8 <div class="field form_input {{class}}">
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}} {{kwargs|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>
55 {% endfor %} 55 {% endfor %}
56 </div> 56 </div>
57 {% endmacro %} 57 {% endmacro %}
58 58
59 {% macro int(name, label="", init=0) %} 59 {% macro int(name, label="", init=0) %}
60 {{ field("number", name=name, label=label, value=init, step=1, min=0, **kwargs) }} 60 {{ field("number", name=name, label=label, value=init, step=1, min=0) }}
61 {% endmacro %} 61 {% endmacro %}
62 62
63 {% macro checkbox(name, label="", checked=false) %} 63 {% macro checkbox(name, label="", checked=false) %}
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="", placeholder="", required=false) %} 69 {% macro text(name, label="", value=none, class='', placeholder=none, required=false, icon_left=none, icon_right=none) %}
70 {{ field("text", name=name, label=label, required=required, placeholder=placeholder, **kwargs) }} 70 {{ field("text", name=name, label=label, value=value, class=class, required=required, icon_left=icon_left, icon_right=icon_right, attrs={'placeholder': placeholder}) }}
71 {% endmacro %} 71 {% endmacro %}
72 72
73 {% macro password(name, label="", required=false) %} 73 {% macro password(name, label="", required=false, icon_left=none, icon_right=none) %}
74 {{ field("password", name=name, label=label, required=required, **kwargs) }} 74 {{ field("password", name=name, label=label, required=required, icon_left=icon_left, icon_right=icon_right) }}
75 {% endmacro %} 75 {% endmacro %}
76 76
77 {% macro email(name, label="", required=false) %} 77 {% macro email(name, label="", required=false) %}
78 {{ field("email", name=name, label=label, required=required, **kwargs) }} 78 {{ field("email", name=name, label=label, required=required) }}
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, **kwargs) }} 82 {{ field("date", name=name, label=label, required=required) }}
83 {% endmacro %} 83 {% endmacro %}
84 84
85 {% macro url(name, label="", required=false) %} 85 {% macro url(name, label="", class="", placeholder=none, required=false, title=none, pattern=none) %}
86 {{ field("url", name=name, label=label, required=required, **kwargs) }} 86 {{ field("url", name=name, label=label, required=required, attrs={'placeholder': placeholder, 'title': title, 'pattern': pattern}) }}
87 {% endmacro %} 87 {% endmacro %}
88 88
89 {% macro file(name, label="", required=false) %} 89 {% macro file(name, label="", required=false) %}
90 {{ field("file", name=name, label=label, required=required, **kwargs) }} 90 {{ field("file", name=name, label=label, required=required) }}
91 {% endmacro %} 91 {% endmacro %}
92 92
93 {% macro textarea(name, label="", rows=none, cols=50, placeholder='', help='', required=false) %} 93 {% macro textarea(name, label="", rows=none, cols=50, placeholder='', help='', required=false) %}
94 <div class="field form_input"> 94 <div class="field form_input">
95 {% set cur_id = name|next_gidx %} 95 {% set cur_id = name|next_gidx %}