@@ -270,10 +270,10 @@ For more information, see :ref:`form-collections-remove`.
270270delete_empty
271271~~~~~~~~~~~~
272272
273- **type **: ``Boolean `` **default **: ``false ``
273+ **type **: ``Boolean `` or `` callable `` **default **: ``false ``
274274
275275If you want to explicitly remove entirely empty collection entries from your
276- form you have to set this option to true. However, existing collection entries
276+ form you have to set this option to `` true `` . However, existing collection entries
277277will only be deleted if you have the allow_delete _ option enabled. Otherwise
278278the empty values will be kept.
279279
@@ -286,6 +286,27 @@ the empty values will be kept.
286286 Read about the :ref: `form's empty_data option <reference-form-option-empty-data >`
287287 to learn why this is necessary.
288288
289+ A value is deleted from the collection only if the normalized value is ``null ``.
290+ However, you can also set the option value to a ``callable ``, which will be called
291+ for each value in the submitted collection. The ``callable `` should return
292+ whether or not a value must be removed from the collection. For example::
293+
294+ use Symfony\Component\Form\Extension\Core\Type\CollectionType;
295+ // ...
296+
297+ $builder->add('users', CollectionType::class, array(
298+ // ...
299+ 'delete_empty' => function (User $user = null) {
300+ return null === $user || empty($user->getFirstName());
301+ },
302+ ));
303+
304+ Using a ``callable `` is particularly useful in case of a compound form type
305+ which may have complex conditions for being empty.
306+
307+ .. versionadded :: 3.4
308+ Using a ``callable `` as an option value was introduced in Symfony 3.4.
309+
289310entry_options
290311~~~~~~~~~~~~~
291312
0 commit comments