Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 23634e1

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

File tree

Expand file treeCollapse file tree

3 files changed

+25
-10
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+25
-10
lines changed

‎reference/forms/types/collection.rst

Copy file name to clipboardExpand all lines: reference/forms/types/collection.rst
+14Lines 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

Copy file name to clipboardExpand all lines: reference/forms/types/options/empty_data.rst.inc
+5-9Lines 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

Copy file name to clipboardExpand all lines: reference/forms/types/options/required.rst.inc
+6-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.