Files
Froxlor/templates/Froxlor/form/formfields.html.twig
Michael Kaufmann 90d2333eef change port field in ipsandports to type-number
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
2022-02-19 11:15:03 +01:00

101 lines
5.9 KiB
Twig

{% macro bool(id, field) %}
<div class="row mb-3">
<label for="{{ id }}" class="col-sm-4 col-form-label">{{ field.label|raw }}
{% if field.desc is defined and field.desc is not empty %}<br><small>{{ field.desc|raw }}</small>
{% endif %}
</label>
<div class="col-sm-8">
{% if field.is_array is defined and field.is_array == 1 and field.values is not empty %}
{% for subfield in field.values %}
<div class="form-check form-switch">
<input type="checkbox" value="{{ subfield.value }}" name="{{ id }}[]" class="form-check-input" {% if field.value is defined and subfield.value in field.value %} checked="checked" {% endif %} {% if field.visible is defined and field.visible == false %} disabled {% endif %}>
<label class="form-check-label">
{{ subfield.label|raw }}
</label>
</div>
{% endfor %}
{% else %}
<div class="form-check form-switch">
<input type="checkbox" value="{{ field.value }}" id="{{ id }}" name="{{ id }}" class="form-check-input {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" {% if field.checked is defined and field.checked == 1 %} checked="checked" {% endif %} {% if field.visible is defined and field.visible == false %} disabled {% endif %}>
</div>
{% endif %}
</div>
</div>
{% endmacro %}
{% macro plain(id, field) %}
<div class="row mb-3">
<label for="{{ id }}" class="col-sm-4 col-form-label">{{ field.label|raw }}
{% if field.desc is defined and field.desc is not empty %}<br><small>{{ field.desc|raw }}</small>
{% endif %}
</label>
<div class="col-sm-8">
<input type="text" readonly class="form-control-plaintext" id="{{ id }}" value="{{ field.value }}">
</div>
</div>
{% endmacro %}
{% macro input(id, field) %}
<div class="row mb-3">
<label for="{{ id }}" class="col-sm-4 col-form-label">{{ field.label|raw }}
{% if field.desc is defined and field.desc is not empty %}<br><small>{{ field.desc|raw }}</small>
{% endif %}
</label>
<div class="col-sm-8">
<input type="{{ field.type }}" {% if field.type == 'number' and field.min is defined %}min="{{ field.min }}"{% endif %} {% if field.type == 'number' and field.max is defined %}max="{{ field.max }}"{% endif %} id="{{ id }}" name="{{ id }}" value="{{ field.value }}" class="form-control {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" {% if field.mandatory is defined and field.mandatory %} required {% endif %} {% if field.visible is defined and field.visible == false %} disabled {% endif %} {% if field.readonly is defined and field.readonly %} readonly {% endif %} {% if field.autocomplete is defined %} autocomplete="{{ field.autocomplete }}" {% endif %} {% if field.placeholder is defined %} placeholder="{{ field.placeholder }}" {% endif %}/>
</div>
</div>
{% endmacro %}
{% macro input_ul(id, field) %}
{% set max = "" %}
{% if field.maxlength is defined %}
{% for i in 1..field.maxlength %}
{% set max = max ~ "9" %}
{% endfor %}
{% endif %}
<div class="row mb-3">
<label for="{{ id }}" class="col-sm-4 col-form-label">{{ field.label|raw }}
{% if field.desc is defined and field.desc is not empty %}<br><small>{{ field.desc|raw }}</small>
{% endif %}
</label>
<div class="col-sm-8">
<div class="input-group">
<input type="number" min="0" {% if max is not empty %} max="{{ max }}" {% endif %} id="{{ id }}" name="{{ id }}" value="{% if field.value >= 0 %}{{ field.value }}{% endif %}" class="form-control {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" {% if field.mandatory is defined and field.mandatory %} required {% endif %} {% if field.visible is defined and field.visible == false %} disabled {% endif %} {% if field.readonly is defined and field.readonly %} readonly {% endif %} {% if field.autocomplete is defined %} autocomplete="{{ field.autocomplete }}" {% endif %} {% if field.placeholder is defined %} placeholder="{{ field.placeholder }}" {% endif %}/>
<div class="input-group-text">
<input class="form-check-input mt-0" type="checkbox" name="{{ id }}_ul" value="1" {% if field.value == -1 %} checked="checked" {% endif %}>
</div>
</div>
</div>
</div>
{% endmacro %}
{% macro select(id, field) %}
<div class="row mb-3">
<label for="{{ id }}" class="col-sm-4 col-form-label">{{ field.label|raw }}
{% if field.desc is defined and field.desc is not empty %}<br><small>{{ field.desc|raw }}</small>
{% endif %}
</label>
<div class="col-sm-8">
<select class="form-select {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" name="{{ id }}" id="{{ id }}" {% if field.mandatory is defined and field.mandatory %} required {% endif %} {% if field.visible is defined and field.visible == false %} disabled {% endif %}>
{% for val,txt in field.select_var %}
<option value="{{ val }}" {% if field.selected is defined and field.selected == val %} selected="selected" {% endif %}>{{ txt|raw }}</option>
{% endfor %}
</select>
</div>
</div>
{% endmacro %}
{% macro textarea(id, field) %}
<div class="row mb-3">
<label for="{{ id }}" class="col-sm-4 col-form-label">{{ field.label|raw }}
{% if field.desc is defined and field.desc is not empty %}<br><small>{{ field.desc|raw }}</small>
{% endif %}
</label>
<div class="col-sm-8">
<textarea {% if field.rows is defined %} rows="{{ field.rows }}" {% endif %} {% if field.cols is defined %} cols="{{ field.cols }}" {% endif %} id="{{ id }}" name="{{ id }}" class="form-control {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" {% if field.mandatory is defined and field.mandatory %} required {% endif %} {% if field.visible is defined and field.visible == false %} disabled {% endif %} {% if field.readonly is defined and field.readonly %} readonly {% endif %} {% if field.placeholder is defined %} placeholder="{{ field.placeholder }}" {% endif %}>{{ field.value }}</textarea>
</div>
</div>
{% endmacro %}