Skip to content

[Form] Add keep_as_list option #19257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions reference/forms/types/collection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,27 @@ you'd use the :doc:`EmailType </reference/forms/types/email>`. If you want
to embed a collection of some other form, pass the form type class as this
option (e.g. ``MyFormType::class``).

keep_as_list
~~~~~~~~~~~~

**type**: ``boolean`` **default**: ``false``

When set to ``true``, the ``keep_as_list`` option affects the reindexing
of nested form names within a collection. This feature is particularly useful
when working with collection types and removing items from the collection
during form submission.

When this option is set to ``false``, if you have a collection of 3 items and
you remove the second item, the indexes will be ``0`` and ``2`` when validating
the collection. However, by enabling the ``keep_as_list`` option and setting
it to ``true``, the indexes will be reindexed as ``0`` and ``1``. This ensures
that the indexes remain consecutive and do not have gaps, providing a clearer
and more predictable structure for your nested forms.

.. versionadded:: 7.1

The ``keep_as_list`` option was introduced in Symfony 7.1.

prototype
~~~~~~~~~

Expand Down