diff --git a/reference/forms/types/checkbox.rst b/reference/forms/types/checkbox.rst index 541886bbc42..e72400d2684 100644 --- a/reference/forms/types/checkbox.rst +++ b/reference/forms/types/checkbox.rst @@ -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` | @@ -61,4 +62,6 @@ These options inherit from the :doc:`field` 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 diff --git a/reference/forms/types/choice.rst b/reference/forms/types/choice.rst index ad0d611c29f..8c9c924f862 100644 --- a/reference/forms/types/choice.rst +++ b/reference/forms/types/choice.rst @@ -25,6 +25,7 @@ option. | | - `read_only`_ | | | - `disabled`_ | | | - `error_bubbling`_ | +| | - `error_mapping`_ | | | - `mapped`_ | | | - `virtual`_ | | | - `by_reference`_ | @@ -121,6 +122,8 @@ These options inherit from the :doc:`field` 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 diff --git a/reference/forms/types/collection.rst b/reference/forms/types/collection.rst index 10952ded3c4..01f0f46db0b 100644 --- a/reference/forms/types/collection.rst +++ b/reference/forms/types/collection.rst @@ -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`_ | @@ -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 ~~~~~~~~~~~~~~ diff --git a/reference/forms/types/country.rst b/reference/forms/types/country.rst index ccc5a739666..f26700d26c2 100644 --- a/reference/forms/types/country.rst +++ b/reference/forms/types/country.rst @@ -30,6 +30,7 @@ you should just use the ``choice`` type directly. | | - `preferred_choices`_ | | | - `empty_value`_ | | | - `error_bubbling`_ | +| | - `error_mapping`_ | | | - `required`_ | | | - `label`_ | | | - `read_only`_ | @@ -68,6 +69,8 @@ These options inherit from the :doc:`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` type: .. include:: /reference/forms/types/options/required.rst.inc diff --git a/reference/forms/types/date.rst b/reference/forms/types/date.rst index c1719b1c5ac..aa87d713de2 100644 --- a/reference/forms/types/date.rst +++ b/reference/forms/types/date.rst @@ -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 | +----------------------+-----------------------------------------------------------------------------+ @@ -148,3 +149,5 @@ These options inherit from the :doc:`field` 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 diff --git a/reference/forms/types/email.rst b/reference/forms/types/email.rst index 56a406da1bc..94d586886ee 100644 --- a/reference/forms/types/email.rst +++ b/reference/forms/types/email.rst @@ -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` | @@ -43,4 +44,6 @@ These options inherit from the :doc:`field` type: .. include:: /reference/forms/types/options/error_bubbling.rst.inc -.. include:: /reference/forms/types/options/mapped.rst.inc \ No newline at end of file +.. include:: /reference/forms/types/options/error_mapping.rst.inc + +.. include:: /reference/forms/types/options/mapped.rst.inc diff --git a/reference/forms/types/entity.rst b/reference/forms/types/entity.rst index 226bcddd44f..c47382d74c6 100644 --- a/reference/forms/types/entity.rst +++ b/reference/forms/types/entity.rst @@ -30,6 +30,7 @@ objects from the database. | | - `read_only`_ | | | - `disabled`_ | | | - `error_bubbling`_ | +| | - `error_mapping`_ | | | - `mapped`_ | +-------------+------------------------------------------------------------------+ | Parent type | :doc:`choice` | @@ -173,4 +174,6 @@ These options inherit from the :doc:`field` 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 diff --git a/reference/forms/types/file.rst b/reference/forms/types/file.rst index e31714d7b95..f9ff36d3950 100644 --- a/reference/forms/types/file.rst +++ b/reference/forms/types/file.rst @@ -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` | @@ -95,4 +96,6 @@ These options inherit from the :doc:`field` 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 diff --git a/reference/forms/types/hidden.rst b/reference/forms/types/hidden.rst index 3ab10c1db02..a0e954c3bfe 100644 --- a/reference/forms/types/hidden.rst +++ b/reference/forms/types/hidden.rst @@ -15,6 +15,7 @@ The hidden type represents a hidden input field. | Inherited | - `data`_ | | options | - `property_path`_ | | | - `mapped`_ | +| | - `error_mapping`_ | +-------------+----------------------------------------------------------------------+ | Parent type | :doc:`field` | +-------------+----------------------------------------------------------------------+ @@ -48,3 +49,5 @@ These options inherit from the :doc:`date` 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 diff --git a/reference/forms/types/integer.rst b/reference/forms/types/integer.rst index a9f83e232c6..00bd559e67e 100644 --- a/reference/forms/types/integer.rst +++ b/reference/forms/types/integer.rst @@ -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`_ | @@ -73,6 +74,8 @@ These options inherit from the :doc:`field` 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 diff --git a/reference/forms/types/language.rst b/reference/forms/types/language.rst index d5e7397da85..6f606541d06 100644 --- a/reference/forms/types/language.rst +++ b/reference/forms/types/language.rst @@ -31,6 +31,7 @@ you should just use the ``choice`` type directly. | | - `preferred_choices`_ | | | - `empty_value`_ | | | - `error_bubbling`_ | +| | - `error_mapping`_ | | | - `required`_ | | | - `label`_ | | | - `read_only`_ | @@ -69,6 +70,8 @@ These options inherit from the :doc:`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` type: .. include:: /reference/forms/types/options/required.rst.inc diff --git a/reference/forms/types/locale.rst b/reference/forms/types/locale.rst index 7658f7ad4c4..013ca4b6ec0 100644 --- a/reference/forms/types/locale.rst +++ b/reference/forms/types/locale.rst @@ -32,6 +32,7 @@ you should just use the ``choice`` type directly. | | - `preferred_choices`_ | | | - `empty_value`_ | | | - `error_bubbling`_ | +| | - `error_mapping`_ | | | - `required`_ | | | - `label`_ | | | - `read_only`_ | @@ -71,6 +72,8 @@ These options inherit from the :doc:`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` type: .. include:: /reference/forms/types/options/required.rst.inc diff --git a/reference/forms/types/money.rst b/reference/forms/types/money.rst index 285ffa577d1..df489534fa4 100644 --- a/reference/forms/types/money.rst +++ b/reference/forms/types/money.rst @@ -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`_ | @@ -94,6 +95,8 @@ These options inherit from the :doc:`field` 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 diff --git a/reference/forms/types/number.rst b/reference/forms/types/number.rst index 6d9ae5587aa..1dd5234c38b 100644 --- a/reference/forms/types/number.rst +++ b/reference/forms/types/number.rst @@ -20,6 +20,7 @@ you want to use for your number. | | - `read_only`_ | | | - `disabled`_ | | | - `error_bubbling`_ | +| | - `error_mapping`_ | | | - `invalid_message`_ | | | - `invalid_message_parameters`_ | | | - `mapped`_ | @@ -92,6 +93,8 @@ These options inherit from the :doc:`field` 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 diff --git a/reference/forms/types/options/error_mapping.rst.inc b/reference/forms/types/options/error_mapping.rst.inc new file mode 100644 index 00000000000..22f395029b0 --- /dev/null +++ b/reference/forms/types/options/error_mapping.rst.inc @@ -0,0 +1,33 @@ +.. versionadded:: 2.1 + The ``error_mapping`` option is new to Symfony 2.1. + +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. diff --git a/reference/forms/types/password.rst b/reference/forms/types/password.rst index b067bee64e1..8ae6fee67df 100644 --- a/reference/forms/types/password.rst +++ b/reference/forms/types/password.rst @@ -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` | @@ -59,4 +60,6 @@ These options inherit from the :doc:`field` type: .. include:: /reference/forms/types/options/error_bubbling.rst.inc -.. include:: /reference/forms/types/options/mapped.rst.inc \ No newline at end of file +.. include:: /reference/forms/types/options/error_mapping.rst.inc + +.. include:: /reference/forms/types/options/mapped.rst.inc diff --git a/reference/forms/types/percent.rst b/reference/forms/types/percent.rst index 52fe448a495..33e566fbf5f 100644 --- a/reference/forms/types/percent.rst +++ b/reference/forms/types/percent.rst @@ -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`_ | @@ -78,6 +79,8 @@ These options inherit from the :doc:`field` 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 diff --git a/reference/forms/types/radio.rst b/reference/forms/types/radio.rst index 51906275cee..f2fa999e97a 100644 --- a/reference/forms/types/radio.rst +++ b/reference/forms/types/radio.rst @@ -22,6 +22,7 @@ If you want to have a Boolean field, use :doc:`checkbox` | @@ -55,4 +56,6 @@ These options inherit from the :doc:`field` 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 diff --git a/reference/forms/types/repeated.rst b/reference/forms/types/repeated.rst index 32b25ee1365..6f0cc85fe5d 100644 --- a/reference/forms/types/repeated.rst +++ b/reference/forms/types/repeated.rst @@ -25,6 +25,7 @@ accuracy. | Inherited | - `invalid_message`_ | | options | - `invalid_message_parameters`_ | | | - `mapped`_ | +| | - `error_mapping`_ | +-------------+------------------------------------------------------------------------+ | Parent type | :doc:`field` | +-------------+------------------------------------------------------------------------+ @@ -189,3 +190,5 @@ These options inherit from the :doc:`date` 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 diff --git a/reference/forms/types/search.rst b/reference/forms/types/search.rst index f07e886ef90..463e8cbf600 100644 --- a/reference/forms/types/search.rst +++ b/reference/forms/types/search.rst @@ -19,6 +19,7 @@ Read about the input search field at `DiveIntoHTML5.info`_ | | - `read_only`_ | | | - `disabled`_ | | | - `error_bubbling`_ | +| | - `error_mapping`_ | | | - `mapped`_ | +-------------+----------------------------------------------------------------------+ | Parent type | :doc:`text` | @@ -45,6 +46,8 @@ These options inherit from the :doc:`field` 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 .. _`DiveIntoHTML5.info`: http://diveintohtml5.info/forms.html#type-search diff --git a/reference/forms/types/text.rst b/reference/forms/types/text.rst index f5a309c5256..2dd4e1479c3 100644 --- a/reference/forms/types/text.rst +++ b/reference/forms/types/text.rst @@ -16,6 +16,7 @@ The text field represents the most basic input text field. | | - `read_only`_ | | | - `disabled`_ | | | - `error_bubbling`_ | +| | - `error_mapping`_ | | | - `mapped`_ | +-------------+--------------------------------------------------------------------+ | Parent type | :doc:`field` | @@ -43,4 +44,6 @@ These options inherit from the :doc:`field` 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 diff --git a/reference/forms/types/textarea.rst b/reference/forms/types/textarea.rst index 457c4332cdc..2c6f6b6c632 100644 --- a/reference/forms/types/textarea.rst +++ b/reference/forms/types/textarea.rst @@ -16,6 +16,7 @@ Renders a ``textarea`` HTML element. | | - `read_only`_ | | | - `disabled`_ | | | - `error_bubbling`_ | +| | - `error_mapping`_ | | | - `mapped`_ | +-------------+------------------------------------------------------------------------+ | Parent type | :doc:`field` | @@ -42,4 +43,6 @@ These options inherit from the :doc:`field` 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 diff --git a/reference/forms/types/time.rst b/reference/forms/types/time.rst index fb3c92beb32..303a9c29061 100644 --- a/reference/forms/types/time.rst +++ b/reference/forms/types/time.rst @@ -33,6 +33,7 @@ as a ``DateTime`` object, a string, a timestamp or an array. | | - `disabled`_ | | | - `mapped`_ | | | - `virtual`_ | +| | - `error_mapping`_ | +----------------------+-----------------------------------------------------------------------------+ | Parent type | form | +----------------------+-----------------------------------------------------------------------------+ @@ -146,3 +147,5 @@ These options inherit from the :doc:`field` 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 diff --git a/reference/forms/types/timezone.rst b/reference/forms/types/timezone.rst index b1c3359e1ca..535a552f75e 100644 --- a/reference/forms/types/timezone.rst +++ b/reference/forms/types/timezone.rst @@ -30,6 +30,7 @@ you should just use the ``choice`` type directly. | | - `read_only`_ | | | - `disabled`_ | | | - `error_bubbling`_ | +| | - `error_mapping`_ | | | - `mapped`_ | +-------------+------------------------------------------------------------------------+ | Parent type | :doc:`choice` | @@ -73,4 +74,6 @@ These options inherit from the :doc:`field` 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 diff --git a/reference/forms/types/url.rst b/reference/forms/types/url.rst index aefc048f47c..ce25cb82fe3 100644 --- a/reference/forms/types/url.rst +++ b/reference/forms/types/url.rst @@ -20,6 +20,7 @@ have a protocol. | | - `read_only`_ | | | - `disabled`_ | | | - `error_bubbling`_ | +| | - `error_mapping`_ | | | - `mapped`_ | +-------------+-------------------------------------------------------------------+ | Parent type | :doc:`text` | @@ -58,4 +59,6 @@ These options inherit from the :doc:`field` 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