{% load crispy_forms_tags %}
<div class="row g-3">
  {{ errors }}
  {% if errors and not fields %}
    <p>{% for field in hidden_fields %}{{ field }}{% endfor %}</p>
  {% endif %}
  <div class='row'>
  {% for field, errors in fields %}
    {% ifchanged field.field.widget.attrs.category %}
      {% if not forloop.first %}
      <hr>
      {% endif %}
      {% if field.field.widget.attrs.category %}
        <h3 class='col-12'>{{field.field.widget.attrs.category}}</h3>
      {% endif %}
    {% endifchanged %}
    {% if field.field.widget.attrs.position == 'inline' or field.field.widget.attrs.position == 'break' %}
        <div class="col">
    {% elif field.field.widget.attrs.position == 'inorder' %}
        <div class="col-12">
    {% endif %}
        {{ field|as_crispy_field }}
        {% if forloop.last %}
          {% for field in hidden_fields %}{{ field }}{% endfor %}
        {% endif %}
      </div>
      {% if field.field.widget.attrs.position == 'break' %}
      <div class="row"></div>
      {% endif %}

    {% endfor %}
    </div>
  {% if not fields and not errors %}
    {% for field in hidden_fields %}{{ field }}{% endfor %}
  {% endif %}
  <button class="btn btn-primary mb-5" id="form_submit_{{form.instance.id}}" type="submit" hx-post="{% url 'django_form_generator:form_detail' form.instance.id %}">{{form.instance.submit_text}}</button> 
</div>
