first form-migrate tests with customer-add-form

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-02-18 10:42:02 +01:00
parent 28526b4544
commit 829b99bc06
5 changed files with 174 additions and 118 deletions

View File

@@ -0,0 +1,48 @@
{% macro form(form_data, action, title = "") %}
{% import "Froxlor/form/formfields.html.twig" as formfields %}
<form action="{{ action|default("") }}" method="post" enctype="application/x-www-form-urlencoded" class="form">
<div class="card mb-2">
{% if title is not empty %}
<div class="card-header">
{% if form_data.image is not empty %}
<i class="{{ form_data.image }}"></i>
{% endif %}
{{ title }}
</div>
{% endif %}
<div class="card-body">
{% for section in form_data.sections %}
<div class="card mb-3">
{% if section.title is not empty %}
<div class="card-header">
{% if section.image is not empty %}
<i class="{{ section.image }}"></i>
{% endif %}
{{ section.title }}
</div>
{% endif %}
<div class="card-body">
{% for id,field in section.fields %}
{% if field.type == 'text' or field.type == 'password' %}
{{ formfields.input(id, field) }}
{% elseif field.type == 'textul' %}
{{ formfields.input_ul(id, field) }}
{% elseif field.type == 'checkbox' %}
{{ formfields.bool(id, field) }}
{% elseif field.type == 'select' %}
{{ formfields.select(id, field) }}
{% elseif field.type == 'textarea' %}
{{ formfields.textarea(id, field) }}
{% endif %}
{% endfor %}
</div>
</div>
{% endfor %}
</div>
<!-- /card-body -->
</div>
<!-- /card -->
</form>
{% endmacro %}

View File

@@ -0,0 +1,76 @@
{% macro bool(id, field) %}
<div class="row mb-3">
<label for="{{ id }}" class="col-sm-4 col-form-label">{{ field.label|raw }}</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 field.value == subfield.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 input(id, field) %}
<div class="row mb-3">
<label for="{{ id }}" class="col-sm-4 col-form-label">{{ field.label|raw }}</label>
<div class="col-sm-8">
<input type="{{ field.type }}" 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 }}</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 }}</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 %}

View File

@@ -52,7 +52,7 @@
<div class="card-body d-grid gap-2">
<input type="hidden" name="script" value="{{ lastscript }}" />
<input type="hidden" name="qrystr" value="{{ lastqrystr }}" />
<input type="hidden" name="qrystr" value="{{ lastqrystr|raw }}" />
<input type="hidden" name="send" value="send" />
<button class="btn btn-primary rounded-top-0" type="submit" name="dologin">{{ lng('login.login') }}</button>
</div>