Mercurial > libervia-templates
diff 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 |
line wrap: on
line diff
--- a/sat_templates/templates/bulma/input/field.html Thu Jul 16 09:08:34 2020 +0200 +++ b/sat_templates/templates/bulma/input/field.html Thu Jul 16 09:08:34 2020 +0200 @@ -1,17 +1,17 @@ {# macros to create form fields #} -{% macro field(type, name, label="", help="", required=false, icon_left=none, icon_right=none) %} +{% macro field(type, name, label="", value=none, class='', help="", required=false, icon_left=none, icon_right=none, attrs=none) %} {# generic field "class" keyword can be used to add classes additional kwargs will be passed as attributes #} - <div class="field form_input {{kwargs.pop('class', '')}}"> + <div class="field form_input {{class}}"> {% set cur_id = name|next_gidx %} {% if label %} <label for="{{cur_id}}" class="label">{{label}}</label> {% endif %} <div class="control{% if icon_left %} has-icons-left{% endif %}{% if icon_right %} has-icons-right{% endif %}"> - <input id="{{cur_id}}" class="input" type="{{type}}" name="{{name}}" {{"required" if required}} {{kwargs|xmlattr}}> + <input id="{{cur_id}}" class="input" type="{{type}}" name="{{name}}" {{"required" if required}}{{{'value': value}|xmlattr}}{{attrs or {}|xmlattr}}> {% if icon_left %} <span class="icon is-left"> {# we use <i> with font from CSS instead of SVG, because using directly SVG doesn't play way with Bulma's control #} @@ -57,7 +57,7 @@ {% endmacro %} {% macro int(name, label="", init=0) %} - {{ field("number", name=name, label=label, value=init, step=1, min=0, **kwargs) }} + {{ field("number", name=name, label=label, value=init, step=1, min=0) }} {% endmacro %} {% macro checkbox(name, label="", checked=false) %} @@ -66,28 +66,28 @@ <input id="{{cur_id}}" type="checkbox" {% if checked %}checked=checked{% endif %}> {% endmacro %} -{% macro text(name, label="", placeholder="", required=false) %} - {{ field("text", name=name, label=label, required=required, placeholder=placeholder, **kwargs) }} +{% macro text(name, label="", value=none, class='', placeholder=none, required=false, icon_left=none, icon_right=none) %} + {{ field("text", name=name, label=label, value=value, class=class, required=required, icon_left=icon_left, icon_right=icon_right, attrs={'placeholder': placeholder}) }} {% endmacro %} -{% macro password(name, label="", required=false) %} - {{ field("password", name=name, label=label, required=required, **kwargs) }} +{% macro password(name, label="", required=false, icon_left=none, icon_right=none) %} + {{ field("password", name=name, label=label, required=required, icon_left=icon_left, icon_right=icon_right) }} {% endmacro %} {% macro email(name, label="", required=false) %} - {{ field("email", name=name, label=label, required=required, **kwargs) }} + {{ field("email", name=name, label=label, required=required) }} {% endmacro %} {% macro date(name, label="", required=false) %} - {{ field("date", name=name, label=label, required=required, **kwargs) }} + {{ field("date", name=name, label=label, required=required) }} {% endmacro %} -{% macro url(name, label="", required=false) %} - {{ field("url", name=name, label=label, required=required, **kwargs) }} +{% macro url(name, label="", class="", placeholder=none, required=false, title=none, pattern=none) %} +{{ field("url", name=name, label=label, required=required, attrs={'placeholder': placeholder, 'title': title, 'pattern': pattern}) }} {% endmacro %} {% macro file(name, label="", required=false) %} - {{ field("file", name=name, label=label, required=required, **kwargs) }} + {{ field("file", name=name, label=label, required=required) }} {% endmacro %} {% macro textarea(name, label="", rows=none, cols=50, placeholder='', help='', required=false) %}