Skip to content

Commit 5ac001e

Browse files
committed
feature #19257 [Form] Add keep_as_list option (alexandre-daubois)
This PR was merged into the 7.1 branch. Discussion ---------- [Form] Add `keep_as_list` option Fix #19248 Commits ------- 2e45f6a [Form] Add `keep_as_list` option
2 parents c7d3bf8 + 2e45f6a commit 5ac001e

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)