jrief / django-formset

The missing widgets and form manipulation library for Django
https://django-formset.fly.dev/
MIT License
317 stars 30 forks source link

How to use form_collection field by field ? #149

Open shoudini opened 2 months ago

shoudini commented 2 months ago

In the template example we prepared below, CRUD operations can be performed well with the {{ form }} tag as a field by field. However, we cannot perform a similar CRUD operation with the {{ form_collection }} tag.

{% formsetify form %}
<django-formset endpoint="{{ request.path }}" csrf-token="{{ csrf_token }}">
    <form id="{{ form.form_id }}"></form>
    {% include "partials/formset/non_field_errors.html" %}
    {% for field in form %}
        {% if field.is_hidden %}
            {{ field }}
        {% else %}
            {% include "partials/formset/bootstrap/field_group.html" %}  
        {% endif %}
    {% endfor %}
    {% if add %}
        <button type="button" class="btn btn-secondary" df-click="disable -> spinner -> submit({add: true}) -> okay(500) -> proceed !~ enable -> bummer(500)">Kaydet
            <span class="dj-button-decorator ms-2">
                {% static 'images/svg/kaydet.svg' %}
            </span>
        </button>
    {% else %}
        <button type="button" class="btn btn-soft-primary py-2" df-click="submit({update: true}) -> proceed">Güncelle</button>
        <button type="button" name="silinsinmi" aria-describedby="id_ebildirge.silinsinmi_helptext" form="id_ebildirge" id="id_ebildirge.silinsinmi" df-click="activate" class="btn btn-danger">Sil</button>
        {% endif %}
        <button type="button" class="btn btn-soft-primary py-2" df-click="reset">Sıfırla</button>
        <a class="btn btn-soft-primary py-2"  href="{% url 'dashboards:listele' %}">Geri</a>
</django-formset>

In other words, when we try to perform the operation "4.3. Rendering a Django Form Field-by-Field," as shown in the example at https://django-formset.fly.dev/single-form/, for {{ form_collection }}, we encounter an error :

AssertionError at /ebildirge/14/ Must be applied to a Form object inheriting from 'django.forms.BaseForm'. ebildirge_form.html, error at line 36 {% formsetify form %}

Are we missing something? Could you please assist us? Thank you very much in advance.