summaryrefslogtreecommitdiffstats
path: root/templates/w3/field.html
blob: f73441fe6d8286fdc52b5160056a3f1e5136a56d (plain) (blame)
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
{% load crispy_forms_field %}

{% if field.is_hidden %}
    {{ field }}
{% else %}
    {% if field|is_checkbox %}
        <div class="w3-input">
        {% if label_class %}
            <div class="{% for offset in bootstrap_checkbox_offsets %}{{ offset }} {% endfor %}{{ field_class }}">
        {% endif %}
    {% endif %}
    <{% if tag %}{{ tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" class="{% if not field|is_checkbox %}w3-input{% if 'form-horizontal' in form_class %} row{% endif %}{% else %}{%if use_custom_control%}{% if tag != 'td' %}custom-control {%endif%} custom-checkbox{% else %}form-check{% endif %}{% endif %}{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
        {% if field.label and not field|is_checkbox and form_show_labels %}
        {# not field|is_radioselect in row below can be removed once Django 3.2 is no longer supported #}
        <label {% if field.id_for_label and not field|is_radioselect %}for="{{ field.id_for_label }}" {% endif %}class="{% if 'form-horizontal' in form_class %}col-form-label {% endif %}{{ label_class }}{% if field.field.required %} requiredField{% endif %}">
                {{ field.label }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
            </label>
        {% endif %}

        {% if field|is_checkboxselectmultiple %}
            {% include 'w3/layout/checkboxselectmultiple.html' %}
        {% endif %}

        {% if field|is_radioselect %}
            {% include 'w3/layout/radioselect.html' %}
        {% endif %}

        {% if not field|is_checkboxselectmultiple and not field|is_radioselect %}
            {% if field|is_checkbox and form_show_labels %}
                {%if use_custom_control%}
                    {% if field.errors %}
                        {% crispy_field field 'class' 'custom-control-input is-invalid' %}
                    {% else %}
                        {% crispy_field field 'class' 'custom-control-input' %}
                    {% endif %}
                {% else %}
                    {% if field.errors %}
                        {% crispy_field field 'class' 'form-check-input is-invalid' %}
                    {% else %}
                        {% crispy_field field 'class' 'form-check-input' %}
                    {% endif %}
                {% endif %}
                <label for="{{ field.id_for_label }}" class="{%if use_custom_control%}custom-control-label{% else %}form-check-label{% endif %}{% if field.field.required %} requiredField{% endif %}">
                    {{ field.label }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
                </label>
                {% include 'w3/layout/help_text_and_errors.html' %}
            {% elif field|is_file and use_custom_control  %}
                {% include 'w3/layout/field_file.html' %}
            {% else %}
                <div{% if field_class %} class="{{ field_class }}"{% endif %}>
                    {% if field|is_select and use_custom_control %}
                        {% if field.errors %}
                            {% crispy_field field 'class' 'custom-select is-invalid' %}
                        {% else %}
                            {% crispy_field field 'class' 'custom-select' %}
                        {% endif %}
                    {% elif field|is_file %}
                        {% if field.errors %}
                            {% crispy_field field 'class' 'form-control-file is-invalid' %}
                        {% else %}
                            {% crispy_field field 'class' 'form-control-file' %}
                        {% endif %}
                    {% else %}
                        {% if field.errors %}
                            {% crispy_field field 'class' 'form-control is-invalid' %}
                        {% else %}
                            {% crispy_field field 'class' 'form-control' %}
                        {% endif %}
                    {% endif %}
                    {% include 'w3/layout/help_text_and_errors.html' %}
                </div>
            {% endif %}
        {% endif %}
    </{% if tag %}{{ tag }}{% else %}div{% endif %}>
    {% if field|is_checkbox %}
        {% if label_class %}
            </div>
        {% endif %}
        </div>
    {% endif %}
{% endif %}