comparison sat_templates/templates/default/input/field.html @ 164:e9f0a4215e46

multi-sites handling (moved templates to "templates" sub-directory) + noscript styles handling.
author Goffi <goffi@goffi.org>
date Mon, 10 Sep 2018 08:53:33 +0200
parents sat_templates/default/input/field.html@b84d20af0ed3
children 178f55b825b7
comparison
equal deleted inserted replaced
163:33f67228686a 164:e9f0a4215e46
1 {# macros to create form fields #}
2
3 {% macro field(type, name, label="", required=false) %}
4 {# generic field
5 "class" keyword can be used to add classes
6 additional kwargs will be passed as attributes #}
7 <span class="form_input {{kwargs.pop('class', '')}}">
8 {% set cur_id = name|next_gidx %}
9 {% if label %}
10 <label for="{{cur_id}}" {{'class="required"'|safe if required}}>{{label}}</label>
11 {% endif %}
12 <input id="{{cur_id}}" type="{{type}}" name="{{name}}" {{"required" if required}} {{kwargs|xmlattr}}>
13 </span>
14 {% endmacro %}
15
16 {% macro choices(name, choices_list, checked=none) %}
17 {% for choice, label in choices_list %}
18 <div class="form_input {{kwargs.pop('class', '')}}">
19 <input id="{{name|next_gidx}}" type="radio" name="{{name}}" value="{{choice}}"{{" checked" if checked==choice}}><label for="{{name|cur_gidx}}">{{label}}</label>
20 </div>
21 {% endfor %}
22 {% endmacro %}
23
24 {% macro int(name, label="", init=0) %}
25 {{ field("number", name=name, label=label, value=init, step=1, min=0, **kwargs) }}
26 {% endmacro %}
27
28 {% macro checkbox(name, label="", checked=false) %}
29 {% if checked %}
30 {{ field("checkbox", name=name, label=label, checked="checked", **kwargs) }}
31 {% else %}
32 {{ field("checkbox", name=name, label=label, **kwargs) }}
33 {% endif %}
34 {% endmacro %}
35
36 {% macro text(name, label="", placeholder="", required=false) %}
37 {{ field("text", name=name, label=label, required=required, placeholder=placeholder, **kwargs) }}
38 {% endmacro %}
39
40 {% macro password(name, label="", required=false) %}
41 {{ field("password", name=name, label=label, required=required, **kwargs) }}
42 {% endmacro %}
43
44 {% macro email(name, label="", required=false) %}
45 {{ field("email", name=name, label=label, required=required, **kwargs) }}
46 {% endmacro %}
47
48 {% macro date(name, label="", required=false) %}
49 {{ field("date", name=name, label=label, required=required, **kwargs) }}
50 {% endmacro %}
51
52 {% macro url(name, label="", required=false) %}
53 {{ field("url", name=name, label=label, required=required, **kwargs) }}
54 {% endmacro %}
55
56 {% macro file(name, label="", required=false) %}
57 {{ field("file", name=name, label=label, required=required, **kwargs) }}
58 {% endmacro %}
59
60 {% macro textarea(name, label="", rows=10, cols=50, placeholder='', required=false) %}
61 <div class="form_input {{kwargs.pop('class', '')}}">
62 {% set cur_id = name|next_gidx %}
63 {% if label %}
64 <label for="{{cur_id}}" {{'class="required"'|safe if required}}>{{label}}</label>
65 {% endif %}
66 <textarea id="{{cur_id}}" name="{{name}}" rows="{{rows}}" cols="{{cols}}" placeholder="{{placeholder}}" {{"required" if required}} class="{{kwargs.pop('class', '')}}"></textarea>
67 </div>
68 {% endmacro %}
69
70 {% macro meta(name, value) %}
71 <input type="hidden" name="{{name}}" value="{{value}}">
72 {% endmacro %}
73
74 {% macro submit(text=_("Send")) %}
75 <input class="form_submit button" type="submit" value="{{text}}" class="{{kwargs.pop('class', '')}}">
76 {% endmacro %}