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
Show file tree
Hide file tree
Changes from 4 commits
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
3 changes: 3 additions & 0 deletions reference/forms/types/checkbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ if the box is unchecked, the value will be set to false.
| | - `read_only`_ |
| | - `disabled`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `mapped`_ |
+-------------+------------------------------------------------------------------------+
| Parent type | :doc:`field</reference/forms/types/form>` |
Expand Down Expand Up @@ -61,4 +62,6 @@ These options inherit from the :doc:`field</reference/forms/types/form>` type:

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

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

.. include:: /reference/forms/types/options/mapped.rst.inc
3 changes: 3 additions & 0 deletions reference/forms/types/choice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ option.
| | - `read_only`_ |
| | - `disabled`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `mapped`_ |
| | - `virtual`_ |
| | - `by_reference`_ |
Expand Down Expand Up @@ -121,6 +122,8 @@ These options inherit from the :doc:`field</reference/forms/types/form>` type:

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

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

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

.. include:: /reference/forms/types/options/virtual.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/collection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ forms, which is useful when creating forms that expose one-to-many relationships
+-------------+-----------------------------------------------------------------------------+
| Inherited | - `label`_ |
| options | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `by_reference`_ |
| | - `empty_data`_ |
| | - `mapped`_ |
Expand Down Expand Up @@ -345,6 +346,8 @@ Not all options are listed here - only the most applicable to this type:

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

.. include:: /reference/forms/types/options/_error_mapping.rst.inc

error_bubbling
~~~~~~~~~~~~~~

Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/country.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ you should just use the ``choice`` type directly.
| | - `preferred_choices`_ |
| | - `empty_value`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `required`_ |
| | - `label`_ |
| | - `read_only`_ |
Expand Down Expand Up @@ -68,6 +69,8 @@ These options inherit from the :doc:`choice</reference/forms/types/choice>` type

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

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

These options inherit from the :doc:`date</reference/forms/types/form>` type:

.. include:: /reference/forms/types/options/required.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/date.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ day, and year) or three select boxes (see the `widget_` option).
| | - `disabled`_ |
| | - `mapped`_ |
| | - `virtual`_ |
| | - `error_mapping`_ |
+----------------------+-----------------------------------------------------------------------------+
| Parent type | ``field`` (if text), ``form`` otherwise |
+----------------------+-----------------------------------------------------------------------------+
Expand Down Expand Up @@ -148,3 +149,5 @@ These options inherit from the :doc:`field</reference/forms/types/form>` type:
.. include:: /reference/forms/types/options/mapped.rst.inc

.. include:: /reference/forms/types/options/virtual.rst.inc

.. include:: /reference/forms/types/options/error_mapping.rst.inc
5 changes: 4 additions & 1 deletion reference/forms/types/email.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The ``email`` field is a text field that is rendered using the HTML5
| | - `read_only`_ |
| | - `disabled`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `mapped`_ |
+-------------+---------------------------------------------------------------------+
| Parent type | :doc:`field</reference/forms/types/form>` |
Expand All @@ -43,4 +44,6 @@ These options inherit from the :doc:`field</reference/forms/types/form>` type:

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

.. include:: /reference/forms/types/options/mapped.rst.inc
.. include:: /reference/forms/types/options/error_mapping.rst.inc

.. include:: /reference/forms/types/options/mapped.rst.inc
3 changes: 3 additions & 0 deletions reference/forms/types/entity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ objects from the database.
| | - `read_only`_ |
| | - `disabled`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `mapped`_ |
+-------------+------------------------------------------------------------------+
| Parent type | :doc:`choice</reference/forms/types/choice>` |
Expand Down Expand Up @@ -173,4 +174,6 @@ These options inherit from the :doc:`field</reference/forms/types/form>` type:

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

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

.. include:: /reference/forms/types/options/mapped.rst.inc
3 changes: 3 additions & 0 deletions reference/forms/types/file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The ``file`` type represents a file input in your form.
| | - `read_only`_ |
| | - `disabled`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `mapped`_ |
+-------------+---------------------------------------------------------------------+
| Parent type | :doc:`form</reference/forms/types/form>` |
Expand Down Expand Up @@ -95,4 +96,6 @@ These options inherit from the :doc:`field</reference/forms/types/form>` type:

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

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

.. include:: /reference/forms/types/options/mapped.rst.inc
3 changes: 3 additions & 0 deletions reference/forms/types/hidden.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The hidden type represents a hidden input field.
| Inherited | - `data`_ |
| options | - `property_path`_ |
| | - `mapped`_ |
| | - `error_mapping`_ |
+-------------+----------------------------------------------------------------------+
| Parent type | :doc:`field</reference/forms/types/form>` |
+-------------+----------------------------------------------------------------------+
Expand Down Expand Up @@ -48,3 +49,5 @@ These options inherit from the :doc:`date</reference/forms/types/form>` type:
.. include:: /reference/forms/types/options/property_path.rst.inc

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

.. include:: /reference/forms/types/options/error_mapping.rst.inc
3 changes: 3 additions & 0 deletions reference/forms/types/integer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ integers. By default, all non-integer values (e.g. 6.78) will round down (e.g. 6
| | - `read_only`_ |
| | - `disabled`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `invalid_message`_ |
| | - `invalid_message_parameters`_ |
| | - `mapped`_ |
Expand Down Expand Up @@ -73,6 +74,8 @@ These options inherit from the :doc:`field</reference/forms/types/form>` type:

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

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

.. include:: /reference/forms/types/options/invalid_message.rst.inc

.. include:: /reference/forms/types/options/invalid_message_parameters.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ you should just use the ``choice`` type directly.
| | - `preferred_choices`_ |
| | - `empty_value`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `required`_ |
| | - `label`_ |
| | - `read_only`_ |
Expand Down Expand Up @@ -69,6 +70,8 @@ These options inherit from the :doc:`choice</reference/forms/types/choice>` type

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

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

These options inherit from the :doc:`date</reference/forms/types/form>` type:

.. include:: /reference/forms/types/options/required.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/locale.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ you should just use the ``choice`` type directly.
| | - `preferred_choices`_ |
| | - `empty_value`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `required`_ |
| | - `label`_ |
| | - `read_only`_ |
Expand Down Expand Up @@ -71,6 +72,8 @@ These options inherit from the :doc:`choice</reference/forms/types/choice>` type

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

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

These options inherit from the :doc:`date</reference/forms/types/form>` type:

.. include:: /reference/forms/types/options/required.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/money.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ how the input and output of the data is handled.
| | - `read_only`_ |
| | - `disabled`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `invalid_message`_ |
| | - `invalid_message_parameters`_ |
| | - `mapped`_ |
Expand Down Expand Up @@ -94,6 +95,8 @@ These options inherit from the :doc:`field</reference/forms/types/form>` type:

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

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

.. include:: /reference/forms/types/options/invalid_message.rst.inc

.. include:: /reference/forms/types/options/invalid_message_parameters.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/number.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ you want to use for your number.
| | - `read_only`_ |
| | - `disabled`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `invalid_message`_ |
| | - `invalid_message_parameters`_ |
| | - `mapped`_ |
Expand Down Expand Up @@ -92,6 +93,8 @@ These options inherit from the :doc:`field</reference/forms/types/form>` type:

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

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

.. include:: /reference/forms/types/options/invalid_message.rst.inc

.. include:: /reference/forms/types/options/invalid_message_parameters.rst.inc
Expand Down
33 changes: 33 additions & 0 deletions reference/forms/types/options/error_mapping.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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 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 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)

5 changes: 4 additions & 1 deletion reference/forms/types/password.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The ``password`` field renders an input password text box.
| | - `read_only`_ |
| | - `disabled`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `mapped`_ |
+-------------+------------------------------------------------------------------------+
| Parent type | :doc:`text</reference/forms/types/text>` |
Expand Down Expand Up @@ -59,4 +60,6 @@ These options inherit from the :doc:`field</reference/forms/types/form>` type:

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

.. include:: /reference/forms/types/options/mapped.rst.inc
.. include:: /reference/forms/types/options/error_mapping.rst.inc

.. include:: /reference/forms/types/options/mapped.rst.inc
3 changes: 3 additions & 0 deletions reference/forms/types/percent.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This field adds a percentage sign "``%``" after the input box.
| | - `read_only`_ |
| | - `disabled`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `invalid_message`_ |
| | - `invalid_message_parameters`_ |
| | - `mapped`_ |
Expand Down Expand Up @@ -78,6 +79,8 @@ These options inherit from the :doc:`field</reference/forms/types/form>` type:

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

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

.. include:: /reference/forms/types/options/invalid_message.rst.inc

.. include:: /reference/forms/types/options/invalid_message_parameters.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/radio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ If you want to have a Boolean field, use :doc:`checkbox</reference/forms/types/c
| | - `read_only`_ |
| | - `disabled`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `mapped`_ |
+-------------+---------------------------------------------------------------------+
| Parent type | :doc:`field</reference/forms/types/form>` |
Expand Down Expand Up @@ -55,4 +56,6 @@ These options inherit from the :doc:`field</reference/forms/types/form>` type:

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

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

.. include:: /reference/forms/types/options/mapped.rst.inc
3 changes: 3 additions & 0 deletions reference/forms/types/repeated.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ accuracy.
| Inherited | - `invalid_message`_ |
| options | - `invalid_message_parameters`_ |
| | - `mapped`_ |
| | - `error_mapping`_ |
+-------------+------------------------------------------------------------------------+
| Parent type | :doc:`field</reference/forms/types/form>` |
+-------------+------------------------------------------------------------------------+
Expand Down Expand Up @@ -189,3 +190,5 @@ These options inherit from the :doc:`date</reference/forms/types/form>` type:
.. include:: /reference/forms/types/options/invalid_message_parameters.rst.inc

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

.. include:: /reference/forms/types/options/error_mapping.rst.inc
Loading