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
Next Next commit
Create error_mapping.rst.inc
| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | yes
| Applies to    | 2.1+
| Fixed tickets | ~

see http://symfony.com/blog/form-goodness-in-symfony-2-1#error-mapping-fu
  • Loading branch information
docteurklein committed Jun 4, 2013
commit 267105f515a377a03e5fa0422f35602f78ad7f86
23 changes: 23 additions & 0 deletions reference/forms/types/options/error_mapping.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error_mapping
~~~~~~~~~~~~~

**type**: ``array`` **default**: ``empty``

This option permits to modify the default target of errors.

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.

Here are to understand the left and the right side of the mapping:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here are the rules to understand.


* 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].
Copy link
Member

Choose a reason for hiding this comment

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

put those classnames and code things inside literals (double quotes)

* 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.