{% extends DYFORM_BASE_TEMPLATE %}
{% load static %}
{% load dynaform %}
{% block content %}
<div class="dynaform-form">
    <h3 class="mb-5 h4 font-weight-bold">DynaForm Data [{{ dynaform.name }}]</h3>
    <form
        action="{% if edit %}{% url 'dynaform-data-edit' dynaform.name dynaform_data.id %}{% else %}{% url 'dynaform-data-delete' dynaform.name dynaform_data.id %}{% endif %}"
        method="POST" class="p-5 bg-light">
        {% csrf_token %}
        {{ form.non_field_errors }}
        {% for field in form.fields %}
        <div class="mb-3 dynaform-form-control-item">
            <label class="form-label" for="{{ form|id_for_label:field }}" {% if form|field_errors:field %}
                style="color:red" {% endif %}>
                {{ form|field_label:field}}:
            </label>
            {% if edit %}
            {{ form|form_field:field }}
            <div style="color:red">{{ form|field_errors:field }}</div>
            {% else %}
            {{ form.data|get_item:field}}
            {% endif %}
        </div>
        {% endfor %}
        <div class="form-group">
            {% if edit %}
            <input type="submit" value="Save" class="btn py-3 px-4 btn-primary">
            {% else %}
            Are you sure you want to delete this item?
            <input type="submit" value="Yes" class="btn py-3 px-4 btn-danger">
            {% endif %}
            <a href='{% url "dynaform-data-list" dynaform.name %}'> Cancel and go to list of {{dynaform.name}}.</a>
        </div>
    </form>
</div>
{% endblock %}