@@ -6,28 +6,35 @@ error_mapping
6
6
7
7
**type**: ``array`` **default**: ``empty``
8
8
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