=============
Configuration
=============
First prepare your Django templates to use a supported `HTML structure`_, and then
`initialise the formsets`_ using the configuration `options`_ to customise how your
formset works.
HTML Structure
==============
By default, django-fancy-formset would like you to construct your formset in a specific
way:
.. code-block:: jinja
{# Formset container to target #}
{{ formset.management_form }} {# Add the management form #}
{% for form in formset %}
{% endfor %}
* set a ``data-formset="prefix"`` attribute on the formset container so it can be found
by ``init()``
* put each form in its own ``fieldset`` container, as direct children of the formset
container
* add a ``formset.empty_form`` in a container as one of the forms, to act as a template
* remember to add the ``formset.management_form`` somewhere
It doesn't matter what your formset forms look like, just as long as they're in a
container.
If you want to construct your formset differently, you can :doc:`extend the classes
` to override the defaults.
.. note::
All inline ``style="..."`` attributes are removed from the empty form container when
it is copied, so you can set ``style="display: none"`` on the empty form to hide it.
If you want to add styles to the form container, you should use CSS classes. If you
want to hide it in a different way, see `options`_, :doc:`events` and
:doc:`extending`.
Styling your formset
--------------------
There is a default stylesheet available which:
* Adds some basic fieldset styling to make your form clearer to use
* Styles the delete button to hide the form being deleted
* Styles the add button
This is available as ``formset.min.css`` if you want to use it directly, or
``formset.css`` (or ``src/formset.scss`` in github) if you want to use it as a starting
point.
Initialise the formsets
=======================
If your formsets follow the expected HTML structure above, you can initialise all of the
formsets on a page at once by calling ``init()`` with no arguments.
For example, you can do this in the HTML from the bottom of your ``body`` tag:
.. code-block:: html