8000 Enhanced documentation to clearify the require option and added the o… · symfony/symfony-docs@23634e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 23634e1

Browse files
peterrehmweaverryan
authored andcommitted
Enhanced documentation to clearify the require option and added the option for symfony/symfony#9773
1 parent 00f4d31 commit 23634e1

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

reference/forms/types/collection.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ forms, which is useful when creating forms that expose one-to-many relationships
1919
| | - `allow_delete`_ |
2020
| | - `prototype`_ |
2121
| | - `prototype_name`_ |
22+
| | - `delete_empty`_ |
2223
+-------------+-----------------------------------------------------------------------------+
2324
| Inherited | - `label`_ |
2425
| | - `label_attr`_ |
2526
| options | - `error_bubbling`_ |
2627
| | - `error_mapping`_ |
2728
| | - `by_reference`_ |
2829
| | - `empty_data`_ |
30+
| | - `required`_ |
2931
| | - `mapped`_ |
3032
+-------------+-----------------------------------------------------------------------------+
3133
| Parent type | :doc:`form </reference/forms/types/form>` |
@@ -334,6 +336,16 @@ If you have several collections in your form, or worse, nested collections
334336
you may want to change the placeholder so that unrelated placeholders are not
335337
replaced with the same value.
336338

339+
delete_empty
340+
~~~~~~~~~~~~~~
341+
342+
**type**: ``Boolean`` **default**: ``false``
343+
344+
If you want to explicitly remove entirely empty collection entries from your
345+
form you have to set this option to true. Existing collection entries will
346+
however only be deleted if you have `allow_delete`_ option enabled, otherwise
347+
the empty values will be kept.
348+
337349
Inherited options
338350
-----------------
339351

@@ -359,4 +371,6 @@ error_bubbling
359371

360372
.. include:: /reference/forms/types/options/empty_data.rst.inc
361373

374+
.. include:: /reference/forms/types/options/required.rst.inc
375+
362376
.. include:: /reference/forms/types/options/mapped.rst.inc

reference/forms/types/options/empty_data.rst.inc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@ choice is selected.
88

99
The true default value of this option depends on the field options:
1010

11-
* If ``compound`` is ``true`` and ``data_class`` is set, then ``new $data_class()``;
12-
* If ``compound`` is ``true`` and no ``data_class`` is set, then ``array()``;
13-
* If ``compound`` is ``false``, then ``null``.
11+
* If ``required`` is ``true`` and ``data_class`` is set, then ``new $data_class()``;
12+
* If ``required`` is ``true`` and no ``data_class`` is set, then ``array()``;
13+
* If ``required`` is ``false``, then ``null``.
1414

15-
.. tip::
1615

17-
The ``compound`` option is set to ``true`` when the field actually represents
18-
a collection of fields (e.g. a form of fields).
19-
20-
For example, if you want the ``gender`` field to be set to ``null`` when no
21-
value is selected, you can do it like this:
16+
But you can customize this to your needs. For example, if you want the ``gender`` field to be
17+
set to explicitly ``null`` when no value is selected, you can do it like this:
2218

2319
.. code-block:: php
2420

reference/forms/types/options/required.rst.inc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ This is superficial and independent from validation. At best, if you let Symfony
1010
guess your field type, then the value of this option will be guessed from
1111
your validation information.
1212

13-
.. _`HTML5 required attribute`: http://diveintohtml5.info/forms.html
13+
.. _`HTML5 required attribute`: http://diveintohtml5.info/forms.html
14+
15+
.. note::
16+
17+
The required option does also affect the way how empty data of your form is
18+
being handled. For further details check the :doc:` empty_data</reference/forms/types/options/empty_data.rst.inc>` option.

0 commit comments

Comments
 (0)
0