engelsystem/resources/views/macros/form.twig

84 lines
3.0 KiB
Twig
Raw Normal View History

{% 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 }}</label>
{%- endif %}
2020-06-01 15:13:21 +02:00
<input
type="{{ type|default('text') }}" class="form-control"
id="{{ name }}" name="{{ name }}"
value="{{ opt.value|default('')|escape('html_attr') }}"
2020-11-24 17:27:21 +01:00
{%- if opt.min is defined %} minlength="{{ opt.min }}"{% endif %}
2020-06-01 15:13:21 +02:00
{%- if opt.required|default(false) %}
required
{%- endif -%}
{%- if opt.disabled|default(false) %}
disabled
{%- endif -%}
{%- if opt.readonly|default(false) %}
readonly
{%- endif -%}
2019-10-08 16:17:06 +02:00
>
</div>
{%- endmacro %}
2019-10-08 16:17:06 +02:00
2020-04-05 16:54:45 +02:00
{% macro textarea(name, label, opt) %}
<div class="mb-3">
2020-04-05 16:54:45 +02:00
{% if label -%}
<label class="form-label" for="{{ name }}">{{ label }}</label>
2020-04-05 16:54:45 +02:00
{%- endif %}
<textarea class="form-control" id="{{ name }}" name="{{ name }}"
2020-06-01 15:13:21 +02:00
{%- if opt.required|default(false) %}
required
{%- endif -%}
{%- if opt.rows|default(0) %}
rows="{{ opt.rows }}"
{%- endif -%}
2020-04-05 16:54:45 +02:00
>{{ opt.value|default('') }}</textarea>
</div>
{%- endmacro %}
{% macro select(name, data, label, selected) %}
<div class="mb-3">
{% if label -%}
<label class="form-label" for="{{ name }}">{{ label }}</label>
{% endif %}
<select id="{{ name }}" name="{{ name }}" class="form-control">
{% for value,decription in data -%}
2020-11-21 20:54:04 +01:00
<option value="{{ value }}" {% if value == selected %} selected{% endif %}>{{ decription }}</option>
{% endfor %}
</select>
</div>
{%- endmacro %}
2020-04-05 16:54:45 +02:00
{% macro checkbox(name, label, checked, value) %}
<div class="checkbox">
<label>
<input type="checkbox" id="{{ name }}" name="{{ name }}" value="{{ value|default('1') }}"
2020-06-01 15:13:21 +02:00
{%- if checked|default(false) %} checked{% endif %}
>
2020-04-05 16:54:45 +02:00
{{ label }}
</label>
</div>
{%- endmacro %}
2019-10-08 16:17:06 +02:00
{% macro hidden(name, value) %}
2020-05-01 16:29:28 +02:00
<input type="hidden" id="{{ name }}" name="{{ name }}" value="{{ value|escape('html_attr') }}">
{%- endmacro %}
2019-10-08 16:17:06 +02:00
2020-04-05 16:54:45 +02:00
{% macro button(label, opt) %}
2021-07-24 18:19:53 +02:00
<button
2021-07-29 20:18:40 +02:00
class="btn btn-{{ opt.btn_type|default('secondary') }}
2021-07-24 18:19:53 +02:00
{%- if 'btn_size' in opt %} btn-{{ opt.btn_size }}{% endif %}"
2020-06-01 15:13:21 +02:00
{%- if opt.type is defined %} type="{{ opt.type }}"{% endif %}
{%- if opt.name is defined %} name="{{ opt.name }}"{% endif %}
2020-12-06 00:16:15 +01:00
{%- if opt.title is defined %} title="{{ opt.title }}"{% endif %}
2020-06-01 15:13:21 +02:00
{%- if opt.value is defined or opt.name is defined %} value="{{ opt.value|default('1') }}"{% endif -%}
2020-04-05 16:54:45 +02:00
>
{{ label }}
</button>
{%- endmacro %}
{% macro submit(label, opt) %}
2021-07-29 20:18:40 +02:00
{{ _self.button(label|default(__('form.submit')), opt|default({})|merge({'type': 'submit', 'btn_type': 'primary'})) }}
{%- endmacro %}