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 d7ef1c7

Browse filesBrowse files
committed
feature #4348 Updated information about handling validation of embedded forms to Valid... (peterrehm)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #4348). Discussion ---------- Updated information about handling validation of embedded forms to Valid... | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | all | Fixed tickets | #4346 Applied Valid constraint instead of the cascade_validation option since this option is supposed to be deprecated with symfony/symfony#12237 Commits ------- b699731 Updated information about handling validation of embedded forms to Valid constraint
2 parents 23afdb3 + b699731 commit d7ef1c7
Copy full SHA for d7ef1c7

File tree

Expand file treeCollapse file tree

2 files changed

+17
-12
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-12
lines changed

‎book/forms.rst

Copy file name to clipboardExpand all lines: book/forms.rst
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,8 @@ objects. For example, a registration form may contain data belonging to
12341234
a ``User`` object as well as many ``Address`` objects. Fortunately, this
12351235
is easy and natural with the Form component.
12361236

1237+
.. _forms-embedding-single-object:
1238+
12371239
Embedding a Single Object
12381240
~~~~~~~~~~~~~~~~~~~~~~~~~
12391241

@@ -1263,6 +1265,7 @@ Next, add a new ``category`` property to the ``Task`` class::
12631265

12641266
/**
12651267
* @Assert\Type(type="Acme\TaskBundle\Entity\Category")
1268+
* @Assert\Valid()
12661269
*/
12671270
protected $category;
12681271

@@ -1279,6 +1282,12 @@ Next, add a new ``category`` property to the ``Task`` class::
12791282
}
12801283
}
12811284

1285+
.. tip::
1286+
1287+
The ``Valid`` Constraint has been added to the property ``category``. This
1288+
cascades the validation to the corresponding entity. If you omit this constraint
1289+
the child entity would not be validated.
1290+
12821291
Now that your application has been updated to reflect the new requirements,
12831292
create a form class so that a ``Category`` object can be modified by the user::
12841293

@@ -1326,16 +1335,7 @@ class:
13261335
}
13271336
13281337
The fields from ``CategoryType`` can now be rendered alongside those from
1329-
the ``TaskType`` class. To activate validation on CategoryType, add
1330-
the ``cascade_validation`` option to ``TaskType``::
1331-
1332-
public function setDefaultOptions(OptionsResolverInterface $resolver)
1333-
{
1334-
$resolver->setDefaults(array(
1335-
'data_class' => 'Acme\TaskBundle\Entity\Task',
1336-
'cascade_validation' => true,
1337-
));
1338-
}
1338+
the ``TaskType`` class.
13391339

13401340
Render the ``Category`` fields in the same way as the original ``Task`` fields:
13411341

‎reference/forms/types/options/cascade_validation.rst.inc

Copy file name to clipboardExpand all lines: reference/forms/types/options/cascade_validation.rst.inc
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ For example, if you have a ``ProductType`` with an embedded ``CategoryType``,
88
setting ``cascade_validation`` to ``true`` on ``ProductType`` will cause
99
the data from ``CategoryType`` to also be validated.
1010

11-
Instead of using this option, you can also use the ``Valid`` constraint in
12-
your model to force validation on a child object stored on a property.
11+
.. tip::
12+
13+
Instead of using this option, it is recommended that you use the ``Valid``
14+
constraint in your model to force validation on a child object stored on
15+
a property. This cascades only the validation but not the use of the
16+
``validation_group`` option on child forms. You can read more about this
17+
in the section about :ref:`Embedding a Single Object <forms-embedding-single-object>`.
1318

1419
.. include:: /reference/forms/types/options/_error_bubbling_hint.rst.inc
1520

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.