Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit7ae32e2

Browse files
committed
[#2694] Fixing some formatting issues and some minor proofreading for new error_mapping docs
1 parent0c0ebda commit7ae32e2

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 permitsto modify the default targetof errors.
10-
11-
Imagine a custom method named ``matchingCityAndZipCode`` validates
12-
whether the cityand zip code matches.
13-
Unfortunately, thereis no"matchingCityAndZipCode" fieldin your form,
14-
soall that Symfony candofor youis display the error on topof the form.
15-
16-
With customized error mapping, you cando better:
17-
make the error be mappedto the city field.
18-
19-
Here are the rulesto understand the leftand the right sideof the mapping:
20-
21-
* The left side containsproperty paths.
22-
*If the violationis generated on apropertyor methodof aclass,
23-
its pathis simply propertyName.
24-
*If the violationis generated on an entryof an ``array``
25-
or ``ArrayAccess``object, theproperty pathis ``[indexName]``.
26-
* You can construct nestedproperty paths by concatenating them,
27-
separating properties by dots,
28-
*for example: ``addresses[work].matchingCityAndZipCode``
29-
* The left sideof the error mapping also accepts a dot ``.``,
30-
which refersto the field itself.
31-
That means that any error addedto the fieldis addedto the given
32-
nested field instead.
33-
* The right side contains simply the namesof fieldsin 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)

[8]ページ先頭

©2009-2025 Movatter.jp