From d2b57be9ea9fe619591ca082c3f4d2b70a087c8e Mon Sep 17 00:00:00 2001 From: WouterJ Date: Tue, 18 Feb 2014 17:25:30 +0100 Subject: [PATCH 01/15] Documented missing FormType variables --- reference/forms/twig_reference.rst | 102 +++++++++++++++++------------ 1 file changed, 60 insertions(+), 42 deletions(-) diff --git a/reference/forms/twig_reference.rst b/reference/forms/twig_reference.rst index e33b6b5f1c0..0da054b1c85 100644 --- a/reference/forms/twig_reference.rst +++ b/reference/forms/twig_reference.rst @@ -295,47 +295,65 @@ object: get('name')->vars['label'] ?> -+-----------------+-----------------------------------------------------------------------------------------+ -| Variable | Usage | -+=================+=========================================================================================+ -| ``id`` | The ``id`` HTML attribute to be rendered | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``name`` | The name of the field (e.g. ``title``) - but not the ``name`` | -| | HTML attribute, which is ``full_name`` | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``full_name`` | The ``name`` HTML attribute to be rendered | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``errors`` | An array of any errors attached to *this* specific field (e.g. ``form.title.errors``). | -| | Note that you can't use ``form.errors`` to determine if a form is valid, | -| | since this only returns "global" errors: some individual fields may have errors | -| | Instead, use the ``valid`` option | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``valid`` | Returns ``true`` or ``false`` depending on whether the whole form is valid | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``value`` | The value that will be used when rendering (commonly the ``value`` HTML attribute) | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``read_only`` | If ``true``, ``readonly="readonly"`` is added to the field | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``disabled`` | If ``true``, ``disabled="disabled"`` is added to the field | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``required`` | If ``true``, a ``required`` attribute is added to the field to activate HTML5 | -| | validation. Additionally, a ``required`` class is added to the label. | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``max_length`` | Adds a ``maxlength`` HTML attribute to the element | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``pattern`` | Adds a ``pattern`` HTML attribute to the element | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``label`` | The string label that will be rendered | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``multipart`` | If ``true``, ``form_enctype`` will render ``enctype="multipart/form-data"``. | -| | This only applies to the root form element. | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``attr`` | A key-value array that will be rendered as HTML attributes on the field | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``label_attr`` | A key-value array that will be rendered as HTML attributes on the label | -+-----------------+-----------------------------------------------------------------------------------------+ -| ``compound`` | Whether or not a field is actually a holder for a group of children fields | -| | (for example, a ``choice`` field, which is actually a group of checkboxes | -+-----------------+-----------------------------------------------------------------------------------------+ +.. versionadded:: 2.3 + The ``method`` and ``action`` variables were introduced in Symfony 2.3. + ++------------------------+-------------------------------------------------------------------------------------+ +| Variable | Usage | ++========================+=====================================================================================+ +| ``form`` | The current FormView instance | ++------------------------+-------------------------------------------------------------------------------------+ +| ``id`` | The ``id`` HTML attribute to be rendered | ++------------------------+-------------------------------------------------------------------------------------+ +| ``name`` | The name of the field (e.g. ``title``) - but not the ``name`` | +| | HTML attribute, which is ``full_name`` | ++------------------------+-------------------------------------------------------------------------------------+ +| ``full_name`` | The ``name`` HTML attribute to be rendered | ++------------------------+-------------------------------------------------------------------------------------+ +| ``errors`` | An array of any errors attached to *this* specific field | +| | (e.g. ``form.title.errors``). | +| | Note that you can't use ``form.errors`` to determine if a form is valid, | +| | since this only returns "global" errors: some individual fields may have errors | +| | Instead, use the ``valid`` option | ++------------------------+-------------------------------------------------------------------------------------+ +| ``valid`` | Returns ``true`` or ``false`` depending on whether the whole form is valid | ++------------------------+-------------------------------------------------------------------------------------+ +| ``value`` | The value that will be used when rendering (commonly the ``value`` HTML attribute) | ++------------------------+-------------------------------------------------------------------------------------+ +| ``read_only`` | If ``true``, ``readonly="readonly"`` is added to the field | ++------------------------+-------------------------------------------------------------------------------------+ +| ``disabled`` | If ``true``, ``disabled="disabled"`` is added to the field | ++------------------------+-------------------------------------------------------------------------------------+ +| ``required`` | If ``true``, a ``required`` attribute is added to the field to activate HTML5 | +| | validation. Additionally, a ``required`` class is added to the label. | ++------------------------+-------------------------------------------------------------------------------------+ +| ``max_length`` | Adds a ``maxlength`` HTML attribute to the element | ++------------------------+-------------------------------------------------------------------------------------+ +| ``pattern`` | Adds a ``pattern`` HTML attribute to the element | ++------------------------+-------------------------------------------------------------------------------------+ +| ``label`` | The string label that will be rendered | ++------------------------+-------------------------------------------------------------------------------------+ +| ``multipart`` | If ``true``, ``form_enctype`` will render ``enctype="multipart/form-data"``. | +| | This only applies to the root form element. | ++------------------------+-------------------------------------------------------------------------------------+ +| ``attr`` | A key-value array that will be rendered as HTML attributes on the field | ++------------------------+-------------------------------------------------------------------------------------+ +| ``label_attr`` | A key-value array that will be rendered as HTML attributes on the label | ++------------------------+-------------------------------------------------------------------------------------+ +| ``compound`` | Whether or not a field is actually a holder for a group of children fields | +| | (for example, a ``choice`` field, which is actually a group of checkboxes | ++------------------------+-------------------------------------------------------------------------------------+ +| ``block_prefixes`` | An array of all the names of the parent types | ++------------------------+-------------------------------------------------------------------------------------+ +| ``translation_domain`` | The domain of the translations for this form | ++------------------------+-------------------------------------------------------------------------------------+ +| ``cache_key`` | An unique key which is used for caching | ++------------------------+-------------------------------------------------------------------------------------+ +| ``data`` | The normalized data of the type | ++------------------------+-------------------------------------------------------------------------------------+ +| ``method`` | The method of the current form (POST, GET, etc) | ++------------------------+-------------------------------------------------------------------------------------+ +| ``action`` | The action of the current form (POST, GET, etc) | ++------------------------+-------------------------------------------------------------------------------------+ .. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig From 98e828fcd14ce8c0bd5c68e8b7a9472ef7612e47 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Tue, 18 Feb 2014 17:29:49 +0100 Subject: [PATCH 02/15] Documented checked variable --- reference/forms/types/checkbox.rst | 7 +++++++ reference/forms/types/radio.rst | 7 +++++++ reference/forms/types/variables/checked.rst.inc | 6 ++++++ 3 files changed, 20 insertions(+) create mode 100644 reference/forms/types/variables/checked.rst.inc diff --git a/reference/forms/types/checkbox.rst b/reference/forms/types/checkbox.rst index e39c393dae7..24af9aabfa0 100644 --- a/reference/forms/types/checkbox.rst +++ b/reference/forms/types/checkbox.rst @@ -13,6 +13,8 @@ if the box is unchecked, the value will be set to false. +-------------+------------------------------------------------------------------------+ | Options | - `value`_ | +-------------+------------------------------------------------------------------------+ +| Variables | - `checked`_ | ++-------------+------------------------------------------------------------------------+ | Overridden | - `empty_data`_ | | options | - `compound`_ | +-------------+------------------------------------------------------------------------+ @@ -46,6 +48,11 @@ Field Options .. include:: /reference/forms/types/options/value.rst.inc +Variables +--------- + +.. include:: /reference/forms/types/variables/checked.rst.inc + Overridden options ------------------ diff --git a/reference/forms/types/radio.rst b/reference/forms/types/radio.rst index 0cf937db3bb..4a246088312 100644 --- a/reference/forms/types/radio.rst +++ b/reference/forms/types/radio.rst @@ -15,6 +15,8 @@ If you want to have a Boolean field, use :doc:`checkbox Date: Tue, 18 Feb 2014 18:47:00 +0100 Subject: [PATCH 03/15] Documented choice variables --- reference/forms/types/checkbox.rst | 14 ++++++++----- reference/forms/types/choice.rst | 20 +++++++++++++++++++ reference/forms/types/radio.rst | 14 ++++++++----- .../forms/types/variables/checked.rst.inc | 6 ------ 4 files changed, 38 insertions(+), 16 deletions(-) delete mode 100644 reference/forms/types/variables/checked.rst.inc diff --git a/reference/forms/types/checkbox.rst b/reference/forms/types/checkbox.rst index 24af9aabfa0..7d41b2e46ee 100644 --- a/reference/forms/types/checkbox.rst +++ b/reference/forms/types/checkbox.rst @@ -48,11 +48,6 @@ Field Options .. include:: /reference/forms/types/options/value.rst.inc -Variables ---------- - -.. include:: /reference/forms/types/variables/checked.rst.inc - Overridden options ------------------ @@ -82,3 +77,12 @@ These options inherit from the :doc:`form ` type: .. include:: /reference/forms/types/options/error_mapping.rst.inc .. include:: /reference/forms/types/options/mapped.rst.inc + +Form Variables +-------------- + +======== ============ ============================================ +Variable Type Usage +======== ============ ============================================ +checked ``Boolean`` Whether or not the current input is checked. +======== ============ ============================================ diff --git a/reference/forms/types/choice.rst b/reference/forms/types/choice.rst index c60b2f29f55..5836d203efb 100644 --- a/reference/forms/types/choice.rst +++ b/reference/forms/types/choice.rst @@ -156,3 +156,23 @@ These options inherit from the :doc:`form ` type: .. include:: /reference/forms/types/options/inherit_data.rst.inc .. include:: /reference/forms/types/options/by_reference.rst.inc + +Field Variables +--------------- + +====================== ============ =========================================================== +Variable Type Usage +====================== ============ =========================================================== +multiple ``Boolean`` The value of the `multiple`_ option +expanded ``Boolean`` The value of the `expanded`_ option +preferred_choices ``array`` A nested array containing the ``ChoiceView`` objects of + choices which should be presented to the user with priority +choices ``array`` A nested array containing the ``ChoiceView`` objects of + the remaining choices +separator ``string`` The seperator to use between choice groups +empty_value ``mixed`` The empty value if not already in the list, otherwise + ``null`` +is_selected ``callable`` A callable which takes a ``ChoiceView`` and the value + and returns if the choice is selected or not +empty_value_in_choices ``Boolean`` Whether the empty value is in the choice list +====================== ============ =========================================================== diff --git a/reference/forms/types/radio.rst b/reference/forms/types/radio.rst index 4a246088312..56dacaf7893 100644 --- a/reference/forms/types/radio.rst +++ b/reference/forms/types/radio.rst @@ -34,11 +34,6 @@ If you want to have a Boolean field, use :doc:`checkbox ` type: .. include:: /reference/forms/types/options/error_mapping.rst.inc .. include:: /reference/forms/types/options/mapped.rst.inc + +Form Variables +-------------- + +======== ============ ============================================ +Variable Type Usage +======== ============ ============================================ +checked ``Boolean`` Whether or not the current input is checked. +======== ============ ============================================ diff --git a/reference/forms/types/variables/checked.rst.inc b/reference/forms/types/variables/checked.rst.inc deleted file mode 100644 index ed55f85803c..00000000000 --- a/reference/forms/types/variables/checked.rst.inc +++ /dev/null @@ -1,6 +0,0 @@ -checked -~~~~~~~ - -**type**: boolean - -Whether or not the current input is checked. From 7d10315c548435f5bb849c562338471fe89e2149 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Tue, 18 Feb 2014 20:02:39 +0100 Subject: [PATCH 04/15] Documented selectedchoice test --- reference/forms/twig_reference.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/reference/forms/twig_reference.rst b/reference/forms/twig_reference.rst index 0da054b1c85..a9ceddfaeff 100644 --- a/reference/forms/twig_reference.rst +++ b/reference/forms/twig_reference.rst @@ -192,6 +192,24 @@ good idea to include this in your form tag:
+Form Tests Reference +-------------------- + +Tests can be executed by using the ``is`` operator in Twig to create a +condition. Read `the Twig documentation`_ for more information. + +.. _form-twig-selectedchoice: + +selectedchoice(selected_value) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This test will check if the current choice is equal to the ``selected_value`` +or if the current choice is in the array (when ``selected_value`` is an array). + +.. code-block:: jinja + +