~homeworkprod/byceps

ref: d4c8f7c8475e06080e46c8724a9cfc9247492e42 byceps/byceps/blueprints/common/core/templates/macros/forms.html -rw-r--r-- 2.5 KiB
d4c8f7c8 — Jochen Kupperschmidt Wrap label around checkbox 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{%- from 'macros/icons.html' import render_icon %}


{% macro form_fieldset() -%}
  <fieldset>
{{ caller() }}
  </fieldset>
{%- endmacro %}


{%- macro form_field(field, show_label=True, note=None) -%}
  {%- set kwargs2 = kwargs %}
  {%- call _row(field) %}
        {%- if show_label %}{{ field.label }}{% endif %}{{ field(**kwargs2) }}
        {%- if note %} {{ note|dim }}{% endif %}
  {%- endcall %}
{%- endmacro %}


{%- macro form_field_checkbox(field, label) -%}
  {%- set kwargs2 = kwargs %}
  {%- call _row(field) %}
        <div class="checkbox">
          <label>{{- field(**kwargs2) }} {{ label }}</label>
        </div>
  {%- endcall %}
{%- endmacro %}


{%- macro form_fields_radio(field) -%}
  {%- set kwargs2 = kwargs %}
  {%- for subfield in field %}
        <div class="radio">
    {%- call _row(field) %}
        {{- subfield(**kwargs2) }} {{ subfield.label }}
    {%- endcall %}
        </div>
  {%- endfor %}
{%- endmacro %}


{%- macro _row(field) -%}
      <div class="form-row{% if field.errors %} erroneous{% endif %}">
{{- caller() -}}
        {{- _errors(field) -}}
      </div>
{%- endmacro %}


{%- macro _errors(field) -%}
        {%- if field.errors %}
        <ol class="errors">
          {%- for error in field.errors %}
          <li><strong>{{ _('Error') }}:</strong> <span>{{ error }}</span></li>
          {%- endfor %}
        </ol>
        {%- endif -%}
{%- endmacro %}


{% macro form_supplement(label=None) -%}
      <div class="form-row">
        <div class="label">{% if label is not none %}{{ label }}{% endif %}</div>
        <div class="supplement">
{{ caller() }}
        </div>
      </div>
{%- endmacro %}


{# A field set with a submit button. #}
{% macro form_buttons(label, icon=None, color='primary', cancel_button=False, cancel_url=None) -%}
  <div class="form-buttons">
    <div class="button-row button-row--center button-row--compact">
      <button type="submit" class="button color-{{ color }}">{% if icon %}{{ render_icon(icon) }} {% endif %}<span>{{ label }}</span></button>
    {%- if cancel_button %}
      <button type="button" class="button button--outlined cancel">{{ _('Cancel') }}</button>
    {%- endif %}
    {%- if cancel_url %}
      <a class="button button--outlined" href="{{ cancel_url }}">{{ _('Cancel') }}</a>
    {%- endif %}
    </div>
  </div>
{%- endmacro %}


{% macro form_datalist(id, values) -%}
  <datalist id="{{ id }}">
    {%- for value in values %}
    <option value="{{ value }}">
    {%- endfor %}
  </datalist>
{%- endmacro %}