Mercurial > libervia-templates
annotate sat_templates/templates/bulma/input/field.html @ 363:cddac8502c4b
chat/message: fix urlize escaping on nunjucks:
Nunjucks imply to use `safe` when using `urlize`, while Jinja2 doesn't. Esacaping and safe
filter are added so that `urlize` can work with both engines.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 28 Jun 2023 10:40:53 +0200 |
parents | 1de6a0ecd529 |
children | 58c4c1664421 |
rev | line source |
---|---|
230 | 1 {# macros to create form fields #} |
2 | |
304
cdf88211b86b
bulma (input/field): `field` macro now has `control_class` and `in_group` attributes:
Goffi <goffi@goffi.org>
parents:
296
diff
changeset
|
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) %} |
230 | 4 {# generic field |
5 "class" keyword can be used to add classes | |
6 additional kwargs will be passed as attributes #} | |
7 | |
304
cdf88211b86b
bulma (input/field): `field` macro now has `control_class` and `in_group` attributes:
Goffi <goffi@goffi.org>
parents:
296
diff
changeset
|
8 {% if not in_group %} |
cdf88211b86b
bulma (input/field): `field` macro now has `control_class` and `in_group` attributes:
Goffi <goffi@goffi.org>
parents:
296
diff
changeset
|
9 <div class="field form_input {{class}}"> |
cdf88211b86b
bulma (input/field): `field` macro now has `control_class` and `in_group` attributes:
Goffi <goffi@goffi.org>
parents:
296
diff
changeset
|
10 {% endif %} |
230 | 11 {% set cur_id = name|next_gidx %} |
12 {% if label %} | |
13 <label for="{{cur_id}}" class="label">{{label}}</label> | |
14 {% endif %} | |
304
cdf88211b86b
bulma (input/field): `field` macro now has `control_class` and `in_group` attributes:
Goffi <goffi@goffi.org>
parents:
296
diff
changeset
|
15 <div class="control{% if icon_left %} has-icons-left{% endif %}{% if icon_right %} has-icons-right{% endif %} {{control_class}}"> |
269
edefc1f25219
bulma (input/field): fixed use of `attrs` in `field`, added args, replaced use of `kwargs`
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
16 <input id="{{cur_id}}" class="input" type="{{type}}" name="{{name}}" {{"required" if required}}{{{'value': value}|xmlattr}}{{(attrs or {})|xmlattr}}> |
230 | 17 {% if icon_left %} |
18 <span class="icon is-left"> | |
19 {# we use <i> with font from CSS instead of SVG, because using directly SVG doesn't play way with Bulma's control #} | |
20 <i class="icon-{{icon_left}}"></i> | |
21 </span> | |
22 {% endif %} | |
23 {% if icon_right %} | |
24 <span class="icon is-right"> | |
25 <i class="icon-{{icon_right}}"></i> | |
26 </span> | |
27 {% endif %} | |
28 </div> | |
29 {% if help %} | |
30 <p class="help">{{help}}</p> | |
31 {% endif %} | |
296
fbea1b9a558f
bulma: new search box, used in blog for now
Goffi <goffi@goffi.org>
parents:
269
diff
changeset
|
32 {% if caller %} |
fbea1b9a558f
bulma: new search box, used in blog for now
Goffi <goffi@goffi.org>
parents:
269
diff
changeset
|
33 {{ caller() }} |
fbea1b9a558f
bulma: new search box, used in blog for now
Goffi <goffi@goffi.org>
parents:
269
diff
changeset
|
34 {% endif %} |
304
cdf88211b86b
bulma (input/field): `field` macro now has `control_class` and `in_group` attributes:
Goffi <goffi@goffi.org>
parents:
296
diff
changeset
|
35 {% if not in_group %} |
cdf88211b86b
bulma (input/field): `field` macro now has `control_class` and `in_group` attributes:
Goffi <goffi@goffi.org>
parents:
296
diff
changeset
|
36 </div> |
cdf88211b86b
bulma (input/field): `field` macro now has `control_class` and `in_group` attributes:
Goffi <goffi@goffi.org>
parents:
296
diff
changeset
|
37 {% endif %} |
230 | 38 {% endmacro %} |
39 | |
304
cdf88211b86b
bulma (input/field): `field` macro now has `control_class` and `in_group` attributes:
Goffi <goffi@goffi.org>
parents:
296
diff
changeset
|
40 {% macro select(name, options_list, selected=none, required=false, multiple=false, class="") %} |
230 | 41 {# selection of elements with <select> |
42 | |
43 @param name: name of the field | |
44 @param options_list(list[str, str]): list of name, label of options | |
45 @param selected(none, list): list of select elements | |
46 @param required(bool): true this field is required | |
47 @param multiple(bool): true is multiple selection is possible | |
48 #} | |
269
edefc1f25219
bulma (input/field): fixed use of `attrs` in `field`, added args, replaced use of `kwargs`
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
49 <select name="{{name}}" class="form_input {{class}}" {{"required" if required}}> |
230 | 50 {% for value, label in options_list %} |
51 <option value="{{value}}" {{'selected' if selected and value in selected}}>{{label}}</option> | |
52 {% endfor %} | |
53 </select> | |
54 {% endmacro %} | |
55 | |
304
cdf88211b86b
bulma (input/field): `field` macro now has `control_class` and `in_group` attributes:
Goffi <goffi@goffi.org>
parents:
296
diff
changeset
|
56 {% macro choices(name, choices_list, checked=none, class="") %} |
269
edefc1f25219
bulma (input/field): fixed use of `attrs` in `field`, added args, replaced use of `kwargs`
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
57 <div class="control {{class}}"> |
230 | 58 {% for choice, label in choices_list %} |
59 <label class="radio" for="{{name|cur_gidx}}"> | |
60 <input id="{{name|next_gidx}}" type="radio" name="{{name}}" value="{{choice}}"{{" checked" if checked==choice}}> {{label}} | |
61 </label> | |
62 {% endfor %} | |
63 </div> | |
64 {% endmacro %} | |
65 | |
305
552daa830d42
bulma (input/field): `int` macro has new attributes:
Goffi <goffi@goffi.org>
parents:
304
diff
changeset
|
66 {% macro int(name, label="", init=0, class="", control_class="", placeholder=none, min=none, max=none, step=none, in_group=false) %} |
552daa830d42
bulma (input/field): `int` macro has new attributes:
Goffi <goffi@goffi.org>
parents:
304
diff
changeset
|
67 {{ field("number", name=name, label=label, value=init, class=class, control_class=control_class, in_group=in_group, attrs={"min": min, "max": max, "step": step, "placeholder": placeholder}) }} |
230 | 68 {% endmacro %} |
69 | |
349
2e548a9830c6
(bulma) input/field: fix `name` attribute + add `required` to checkbox
Goffi <goffi@goffi.org>
parents:
317
diff
changeset
|
70 {% macro checkbox(name, label="", checked=false, required=false) %} |
230 | 71 {% set cur_id = name|next_gidx %} |
72 <label for="{{cur_id}}" class="label checkbox">{{label}}</label> | |
349
2e548a9830c6
(bulma) input/field: fix `name` attribute + add `required` to checkbox
Goffi <goffi@goffi.org>
parents:
317
diff
changeset
|
73 <input {{ {"id": cur_id, "name": name}|xmlattr }} type="checkbox" {% if checked %}checked=checked{% endif %} {{"required" if required}}> |
230 | 74 {% endmacro %} |
75 | |
316
81689d346cf6
bulma (input/field): added `help` argument to `text` macro
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
76 {% macro text(name, label="", value=none, class="", control_class="", placeholder=none, help="", required=false, pattern=none, title=none, autocomplete=none, icon_left=none, icon_right=none, in_group=false) %} |
81689d346cf6
bulma (input/field): added `help` argument to `text` macro
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
77 {{ field("text", name=name, label=label, value=value, class=class, control_class=control_class, help=help, required=required, icon_left=icon_left, icon_right=icon_right, attrs={'placeholder': placeholder, 'pattern': pattern, 'title': title, 'autocomplete': autocomplete}, in_group=in_group, caller=caller) }} |
230 | 78 {% endmacro %} |
79 | |
269
edefc1f25219
bulma (input/field): fixed use of `attrs` in `field`, added args, replaced use of `kwargs`
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
80 {% macro password(name, label="", value=none, required=false, minlength=none, icon_left=none, icon_right=none) %} |
edefc1f25219
bulma (input/field): fixed use of `attrs` in `field`, added args, replaced use of `kwargs`
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
81 {{ field("password", name=name, label=label, value=value, required=required, icon_left=icon_left, icon_right=icon_right, attrs={'minlength': minlength}) }} |
230 | 82 {% endmacro %} |
83 | |
350
1de6a0ecd529
(bulma) input/field: add `placeholder` attribute
Goffi <goffi@goffi.org>
parents:
349
diff
changeset
|
84 {% macro email(name, label="", required=false, value=none, placeholder=none, icon_left=none, icon_right=none) %} |
1de6a0ecd529
(bulma) input/field: add `placeholder` attribute
Goffi <goffi@goffi.org>
parents:
349
diff
changeset
|
85 {{ field("email", name=name, label=label, value=value, required=required, icon_left=icon_left, icon_right=icon_right, attrs={'placeholder': placeholder}) }} |
230 | 86 {% endmacro %} |
87 | |
88 {% macro date(name, label="", required=false) %} | |
249
60bf3e45d7b2
bulma (input/field): don't use kwargs anymore:
Goffi <goffi@goffi.org>
parents:
230
diff
changeset
|
89 {{ field("date", name=name, label=label, required=required) }} |
230 | 90 {% endmacro %} |
91 | |
249
60bf3e45d7b2
bulma (input/field): don't use kwargs anymore:
Goffi <goffi@goffi.org>
parents:
230
diff
changeset
|
92 {% macro url(name, label="", class="", placeholder=none, required=false, title=none, pattern=none) %} |
60bf3e45d7b2
bulma (input/field): don't use kwargs anymore:
Goffi <goffi@goffi.org>
parents:
230
diff
changeset
|
93 {{ field("url", name=name, label=label, required=required, attrs={'placeholder': placeholder, 'title': title, 'pattern': pattern}) }} |
230 | 94 {% endmacro %} |
95 | |
96 {% macro file(name, label="", required=false) %} | |
249
60bf3e45d7b2
bulma (input/field): don't use kwargs anymore:
Goffi <goffi@goffi.org>
parents:
230
diff
changeset
|
97 {{ field("file", name=name, label=label, required=required) }} |
230 | 98 {% endmacro %} |
99 | |
304
cdf88211b86b
bulma (input/field): `field` macro now has `control_class` and `in_group` attributes:
Goffi <goffi@goffi.org>
parents:
296
diff
changeset
|
100 {% macro textarea(name, label="", rows=none, cols=50, placeholder="", help="", required=false) %} |
230 | 101 <div class="field form_input"> |
102 {% set cur_id = name|next_gidx %} | |
103 {% if label %} | |
104 <label for="{{cur_id}}" class="label">{{label}}</label> | |
105 {% endif %} | |
106 <textarea id="{{cur_id}}" name="{{name}}" {{ {"rows": rows, "cols": cols}|xmlattr }} placeholder="{{placeholder}}" {{"required" if required}} class="textarea"></textarea> | |
107 {% if help %} | |
108 <p class="help">{{help}}</p> | |
109 {% endif %} | |
110 </div> | |
111 {% endmacro %} | |
112 | |
113 {% macro meta(name, value) %} | |
114 <input type="hidden" name="{{name}}" value="{{value}}"> | |
115 {% endmacro %} | |
116 | |
317
ae903ca0ed66
bulma (input/field): color can now be specified for `submit` button
Goffi <goffi@goffi.org>
parents:
316
diff
changeset
|
117 {% macro submit(text=_("Send"), id=none, class="", icon=none, attrs=none, color="is-primary") %} |
230 | 118 {# submit button |
119 | |
120 @param text(str): label of the button | |
121 @param id(none, str): id of the element | |
122 #} | |
123 <div class="control {{class}}"> | |
317
ae903ca0ed66
bulma (input/field): color can now be specified for `submit` button
Goffi <goffi@goffi.org>
parents:
316
diff
changeset
|
124 <button{{ {'id': id}|xmlattr }} class="button {{color}} form_submit {{class}}" type="submit"{{(attrs or {})|xmlattr}}> |
307
605bce1df126
bulma (input/field): icon can now be specified with `submit` macro
Goffi <goffi@goffi.org>
parents:
306
diff
changeset
|
125 {{text}} |
605bce1df126
bulma (input/field): icon can now be specified with `submit` macro
Goffi <goffi@goffi.org>
parents:
306
diff
changeset
|
126 {% if icon %} |
605bce1df126
bulma (input/field): icon can now be specified with `submit` macro
Goffi <goffi@goffi.org>
parents:
306
diff
changeset
|
127 <span class="icon is-small"> |
605bce1df126
bulma (input/field): icon can now be specified with `submit` macro
Goffi <goffi@goffi.org>
parents:
306
diff
changeset
|
128 <i class="icon-{{icon}}"></i> |
605bce1df126
bulma (input/field): icon can now be specified with `submit` macro
Goffi <goffi@goffi.org>
parents:
306
diff
changeset
|
129 </span> |
605bce1df126
bulma (input/field): icon can now be specified with `submit` macro
Goffi <goffi@goffi.org>
parents:
306
diff
changeset
|
130 {% endif %} |
605bce1df126
bulma (input/field): icon can now be specified with `submit` macro
Goffi <goffi@goffi.org>
parents:
306
diff
changeset
|
131 </button> |
230 | 132 </div> |
133 {% endmacro %} |