112 lines
4.5 KiB
Twig
112 lines
4.5 KiB
Twig
{% macro input(name, label, type, opt) %}
|
|
<div class="mb-3">
|
|
{% if label -%}
|
|
<label for="{{ name }}" class="form-label {% if opt.hide_label|default(false) %}sr-only{% endif %}">
|
|
{{ label }}
|
|
{% if opt.entry_required_icon|default(false) %}
|
|
<span class="bi bi-exclamation-triangle text-info"></span>
|
|
{% endif %}
|
|
</label>
|
|
{%- endif %}
|
|
<input
|
|
type="{{ type|default('text') }}" class="form-control"
|
|
id="{{ name }}" name="{{ name }}"
|
|
value="{{ opt.value|default('')|escape('html_attr') }}"
|
|
{%- if opt.min_length is defined %} minlength="{{ opt.min_length }}"{% endif %}
|
|
{%- if opt.max_length is defined %} maxlength="{{ opt.max_length }}"{% endif %}
|
|
{%- if opt.min is defined %} min="{{ opt.min }}"{% endif %}
|
|
{%- if opt.max is defined %} max="{{ opt.max }}"{% endif %}
|
|
{%- if opt.required|default(false) %}
|
|
required
|
|
{%- endif -%}
|
|
{%- if opt.disabled|default(false) %}
|
|
disabled
|
|
{%- endif -%}
|
|
{%- if opt.readonly|default(false) %}
|
|
readonly
|
|
{%- endif -%}
|
|
>
|
|
</div>
|
|
{%- endmacro %}
|
|
|
|
{% macro textarea(name, label, opt) %}
|
|
<div class="mb-3">
|
|
{% if label -%}
|
|
<label class="form-label" for="{{ name }}">{{ label }}</label>
|
|
{%- endif %}
|
|
<textarea class="form-control" id="{{ name }}" name="{{ name }}"
|
|
{%- if opt.required|default(false) %}
|
|
required
|
|
{%- endif -%}
|
|
{%- if opt.rows|default(0) %}
|
|
rows="{{ opt.rows }}"
|
|
{%- endif -%}
|
|
>{{ opt.value|default('') }}</textarea>
|
|
</div>
|
|
{%- endmacro %}
|
|
|
|
{% macro select(name, data, label, selected, opt) %}
|
|
<div class="mb-3">
|
|
{% if label -%}
|
|
<label class="form-label" for="{{ name }}">{{ label }}</label>
|
|
{% endif %}
|
|
<select id="{{ name }}" name="{{ name }}"
|
|
class="form-control {%- if opt.class is defined %} {{ opt.class }}{% endif %}"
|
|
{%- if opt.required|default(false) %}required{%- endif -%}>
|
|
{%- if opt.default_option is defined %}
|
|
<option value="">{{ opt.default_option }}</option>
|
|
{% endif %}
|
|
{% for value,decription in data -%}
|
|
<option value="{{ value }}"{% if value == selected %} selected{% endif %}>{{ decription }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
{%- endmacro %}
|
|
|
|
{% macro checkbox(name, label, checked, value, disabled, raw_label) %}
|
|
<div class="form-check mb-3">
|
|
<label>
|
|
<input type="checkbox" id="{{ name }}" name="{{ name }}" value="{{ value|default('1') }}" class="form-check-input"
|
|
{%- if checked|default(false) %} checked{% endif %}
|
|
{%- if disabled|default(false) %} disabled{% endif %}
|
|
>
|
|
{%- if raw_label|default(false) -%}
|
|
{{ label|raw }}
|
|
{%- else -%}
|
|
{{ label }}
|
|
{%- endif -%}
|
|
</label>
|
|
</div>
|
|
{%- endmacro %}
|
|
|
|
{% macro hidden(name, value) %}
|
|
<input type="hidden" id="{{ name }}" name="{{ name }}" value="{{ value|escape('html_attr') }}">
|
|
{%- endmacro %}
|
|
|
|
{% macro button(label, opt) %}
|
|
<button
|
|
class="btn btn-{{ opt.btn_type|default('secondary') }}
|
|
{%- if opt.size is defined %} btn-{{ opt.size }}{% endif %}"
|
|
{%- if opt.type is defined %} type="{{ opt.type }}"{% endif %}
|
|
{%- if opt.name is defined %} name="{{ opt.name }}"{% endif %}
|
|
{%- if opt.title is defined %} title="{{ opt.title }}"{% endif %}
|
|
{%- if opt.value is defined or opt.name is defined %} value="{{ opt.value|default('1') }}"{% endif -%}
|
|
>
|
|
{{ label }}
|
|
</button>
|
|
{%- endmacro %}
|
|
|
|
{% macro submit(label, opt) %}
|
|
{{ _self.button(label|default(__('form.submit')), {'type': 'submit', 'btn_type': 'primary'}|merge(opt|default({}))) }}
|
|
{%- endmacro %}
|
|
|
|
{% macro switch(name, label, checked, opt) %}
|
|
<div class="form-check form-switch mb-3">
|
|
<input class="form-check-input" type="checkbox" id="{{ name }}" name="{{ name }}" value="{{ opt.value|default('1') }}"
|
|
{%- if checked|default(false) %} checked{% endif %}
|
|
{%- if opt.disabled|default(false) %} disabled{% endif %}
|
|
>
|
|
<label class="form-check-label" for="{{ name }}">{{ label }}</label>
|
|
</div>
|
|
{%- endmacro %}
|