Skip to content

Commit 2e45f6a

Browse files
[Form] Add keep_as_list option
1 parent c7d3bf8 commit 2e45f6a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

reference/forms/types/collection.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,27 @@ you'd use the :doc:`EmailType </reference/forms/types/email>`. If you want
229229
to embed a collection of some other form, pass the form type class as this
230230
option (e.g. ``MyFormType::class``).
231231

232+
keep_as_list
233+
~~~~~~~~~~~~
234+
235+
**type**: ``boolean`` **default**: ``false``
236+
237+
When set to ``true``, the ``keep_as_list`` option affects the reindexing
238+
of nested form names within a collection. This feature is particularly useful
239+
when working with collection types and removing items from the collection
240+
during form submission.
241+
242+
When this option is set to ``false``, if you have a collection of 3 items and
243+
you remove the second item, the indexes will be ``0`` and ``2`` when validating
244+
the collection. However, by enabling the ``keep_as_list`` option and setting
245+
it to ``true``, the indexes will be reindexed as ``0`` and ``1``. This ensures
246+
that the indexes remain consecutive and do not have gaps, providing a clearer
247+
and more predictable structure for your nested forms.
248+
249+
.. versionadded:: 7.1
250+
251+
The ``keep_as_list`` option was introduced in Symfony 7.1.
252+
232253
prototype
233254
~~~~~~~~~
234255

0 commit comments

Comments
 (0)