Skip to content

add error_mapping form option documentation #2694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 22, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wrap lines
  • Loading branch information
docteurklein committed Jun 13, 2013
commit b634bbcb62fe31c81f95c7d1e53fc7a566d8d41f
30 changes: 20 additions & 10 deletions reference/forms/types/options/error_mapping.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,29 @@ error_mapping

This option permits to modify the default target of errors.

Imagine a custom method named ``matchingCityAndZipCode`` validates whether the city and zip code matches.
Imagine a custom method named ``matchingCityAndZipCode`` validates
whether the city and zip code matches.
Unfortunately, there is no "matchingCityAndZipCode" field in your form,
so all that Symfony can do for you is display the error on top of the form.

With customized error mapping, you can do better: make the error be mapped to the city field.
With customized error mapping, you can do better:
make the error be mapped to the city field.

Here are to understand the left and the right side of the mapping:
Here are the rules to understand the left and the right side of the mapping:

* The left side contains property paths.
* If the violation is generated on a property or method of a class, its path is simply propertyName.
* If the violation is generated on an entry of an array or ArrayAccess object, the property path is [indexName].
* You can construct nested property paths by concatenating them, separating properties by dots,
* for example: addresses[work].matchingCityAndZipCode
*The right side contains simply the names of fields in the form.
* The left side of the error mapping also accepts a dot ., which refers to the field itself.
That means that any error added to the field is added to the given nested field instead.
* If the violation is generated on a property or method of a class,
its path is simply propertyName.
* If the violation is generated on an entry of an ``array``
or ``ArrayAccess`` object, the property path is ``[indexName]``.
* You can construct nested property paths by concatenating them,
separating properties by dots,
* for example: ``addresses[work].matchingCityAndZipCode``
* The left side of the error mapping also accepts a dot ``.``,
which refers to the field itself.
That means that any error added to the field is added to the given
nested field instead.
* The right side contains simply the names of fields in the form.

.. versionadded:: 2.1
The ``error_mapping`` option is new to Symfony 2.1.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put this directive on line 1 (before the title)