Skip to content

Commit 7ae32e2

Browse files
committed
[symfony#2694] Fixing some formatting issues and some minor proofreading for new error_mapping docs
1 parent 0c0ebda commit 7ae32e2

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

reference/forms/types/collection.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ Not all options are listed here - only the most applicable to this type:
346346

347347
.. include:: /reference/forms/types/options/mapped.rst.inc
348348

349-
.. include:: /reference/forms/types/options/_error_mapping.rst.inc
349+
.. include:: /reference/forms/types/options/error_mapping.rst.inc
350350

351351
error_bubbling
352352
~~~~~~~~~~~~~~

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

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,35 @@ error_mapping
66

77
**type**: ``array`` **default**: ``empty``
88

9-
This option permits to modify the default target of errors.
10-
11-
Imagine a custom method named ``matchingCityAndZipCode`` validates
12-
whether the city and zip code matches.
13-
Unfortunately, there is no "matchingCityAndZipCode" field in your form,
14-
so all that Symfony can do for you is display the error on top of the form.
15-
16-
With customized error mapping, you can do better:
17-
make the error be mapped to the city field.
18-
19-
Here are the rules to understand the left and the right side of the mapping:
20-
21-
* The left side contains property paths.
22-
* If the violation is generated on a property or method of a class,
23-
its path is simply propertyName.
24-
* If the violation is generated on an entry of an ``array``
25-
or ``ArrayAccess`` object, the property path is ``[indexName]``.
26-
* You can construct nested property paths by concatenating them,
27-
separating properties by dots,
28-
* for example: ``addresses[work].matchingCityAndZipCode``
29-
* The left side of the error mapping also accepts a dot ``.``,
30-
which refers to the field itself.
31-
That means that any error added to the field is added to the given
32-
nested field instead.
33-
* The right side contains simply the names of fields in the form.
9+
This option allows you to modify the target of a validation error.
10+
11+
Imagine you have a custom method named ``matchingCityAndZipCode`` that validates
12+
whether the city and zip code match. Unfortunately, there is no "matchingCityAndZipCode"
13+
field in your form, so all that Symfony can do is display the error on top
14+
of the form.
15+
16+
With customized error mapping, you can do better: map the error to the city
17+
field so that it displays above it::
18+
19+
public function setDefaultOptions(OptionsResolverInterface $resolver)
20+
{
21+
$resolver->setDefaults(array(
22+
'error_mapping' => array(
23+
'matchingCityAndZipCode' => 'city',
24+
),
25+
));
26+
}
27+
28+
Here are the rules for the left and the right side of the mapping:
29+
30+
* The left side contains property paths.
31+
* If the violation is generated on a property or method of a class, its path
32+
is simply "propertyName".
33+
* If the violation is generated on an entry of an ``array`` or ``ArrayAccess``
34+
object, the property path is ``[indexName]``.
35+
* You can construct nested property paths by concatenating them, separating
36+
properties by dots. For example: ``addresses[work].matchingCityAndZipCode``
37+
* The left side of the error mapping also accepts a dot ``.``, which refers
38+
to the field itself. That means that any error added to the field is added
39+
to the given nested field instead.
40+
* The right side contains simply the names of fields in the form.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy