From 236d06b39b4f2a32705a07c318bc5b3b1cf0cba7 Mon Sep 17 00:00:00 2001 From: mtrojanowski Date: Wed, 5 Feb 2014 16:44:13 +0100 Subject: [PATCH 1/4] Fix the definition of customizing form's global errors. --- cookbook/form/form_customization.rst | 37 +++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/cookbook/form/form_customization.rst b/cookbook/form/form_customization.rst index 7f82fecca81..2879f52d139 100644 --- a/cookbook/form/form_customization.rst +++ b/cookbook/form/form_customization.rst @@ -785,9 +785,40 @@ to just one field) are rendered separately, usually at the top of your form: render($form); ?> To customize *only* the markup used for these errors, follow the same directions -as above, but now call the block ``form_errors`` (Twig) / the file ``form_errors.html.php`` -(PHP). Now, when errors for the ``form`` type are rendered, your customized -fragment will be used instead of the default ``form_errors``. +as above, but now check if the ``compound`` attribute is set to ``true``: + +.. configuration-block:: + + .. code-block:: html+jinja + + {# form_errors.html.twig #} + {% block form_errors %} + {% spaceless %} + {% if errors|length > 0 %} + {% if compound %} + + {% endif %} + {% endif %} + {% endspaceless %} + {% endblock form_errors %} + + .. code-block:: html+php + + + + + + + + Customizing the "Form Row" ~~~~~~~~~~~~~~~~~~~~~~~~~~ From 1e278c423f41891e0664cf31bda065ec792c366e Mon Sep 17 00:00:00 2001 From: Michal Trojanowski Date: Wed, 5 Feb 2014 23:36:26 +0100 Subject: [PATCH 2/4] Added note about customizing errors for different field types. --- cookbook/form/form_customization.rst | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cookbook/form/form_customization.rst b/cookbook/form/form_customization.rst index 2879f52d139..30d326ac5c1 100644 --- a/cookbook/form/form_customization.rst +++ b/cookbook/form/form_customization.rst @@ -771,8 +771,17 @@ and customize the ``form_errors`` fragment. See :ref:`cookbook-form-theming-methods` for how to apply this customization. You can also customize the error output for just one specific field type. -For example, certain errors that are more global to your form (i.e. not specific -to just one field) are rendered separately, usually at the top of your form: +To customize *only* the markup used for these errors, follow the same directions +as above but put the contents in a relative ``_errors`` block (or file in case +of PHP templates). For example: ``text_errors`` (or ``text_errors.html.php``). + +.. tip:: + + See :ref:`form-template-blocks` to find out which specific block or file you + have to customize. + +Certain errors that are more global to your form (i.e. not specific to just one +field) are rendered separately, usually at the top of your form: .. configuration-block:: From e3b20d81fa8091a76ba76cac450aee6b4158d07d Mon Sep 17 00:00:00 2001 From: Michal Trojanowski Date: Thu, 20 Feb 2014 22:08:24 +0100 Subject: [PATCH 3/4] Minor rewording. Added tip about meaning of `compound` var and expanded the example code to contain `else` statements. --- cookbook/form/form_customization.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cookbook/form/form_customization.rst b/cookbook/form/form_customization.rst index 30d326ac5c1..067ac9d6080 100644 --- a/cookbook/form/form_customization.rst +++ b/cookbook/form/form_customization.rst @@ -794,7 +794,13 @@ field) are rendered separately, usually at the top of your form: render($form); ?> To customize *only* the markup used for these errors, follow the same directions -as above, but now check if the ``compound`` attribute is set to ``true``: +as above, but now check if the ``compound`` variable is set to ``true``. + +.. tip:: + + If the ``compound`` variable is ``true``, it means that what's being + currently rendered is a collection of fields (e.g. a whole form), and not + just an individual field. .. configuration-block:: @@ -810,6 +816,8 @@ as above, but now check if the ``compound`` attribute is set to ``true``:
  • {{ error.message }}
  • {% endfor %} + {% else %} + {# display the errors for a single field #} {% endif %} {% endif %} {% endspaceless %} @@ -825,6 +833,8 @@ as above, but now check if the ``compound`` attribute is set to ``true``:
  • getMessage() ?>
  • + + From 6f6fccae5f48620a9132adcf938ee43725df5968 Mon Sep 17 00:00:00 2001 From: Michal Trojanowski Date: Sun, 16 Mar 2014 18:32:22 +0100 Subject: [PATCH 4/4] Applied some changes according to comments. --- cookbook/form/form_customization.rst | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/cookbook/form/form_customization.rst b/cookbook/form/form_customization.rst index 067ac9d6080..554816a1f67 100644 --- a/cookbook/form/form_customization.rst +++ b/cookbook/form/form_customization.rst @@ -794,13 +794,9 @@ field) are rendered separately, usually at the top of your form: render($form); ?> To customize *only* the markup used for these errors, follow the same directions -as above, but now check if the ``compound`` variable is set to ``true``. - -.. tip:: - - If the ``compound`` variable is ``true``, it means that what's being - currently rendered is a collection of fields (e.g. a whole form), and not - just an individual field. +as above, but now check if the ``compound`` variable is set to ``true``. If it +is ``true``, it means that what's being currently rendered is a collection of +fields (e.g. a whole form), and not just an individual field. .. configuration-block:: @@ -817,7 +813,7 @@ as above, but now check if the ``compound`` variable is set to ``true``. {% endfor %} {% else %} - {# display the errors for a single field #} + {# ... display the errors for a single field #} {% endif %} {% endif %} {% endspaceless %} @@ -834,7 +830,7 @@ as above, but now check if the ``compound`` variable is set to ``true``. - +