-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Documented all form variables #3588
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
Changes from 13 commits
d2b57be
98e828f
c8a44ae
7d10315
754da30
3bfdc20
95540ca
1a1497c
e5fded9
a811833
688409e
8b5ecf9
97d216d
398d23f
7710429
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,6 +192,24 @@ good idea to include this in your form tag: | |
|
||
<form action="{{ path('form_submit') }}" method="post" {{ form_enctype(form) }}> | ||
|
||
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 | ||
|
||
<option {% if choice is selectedchoice(value) %} selected="selected"{% endif %} ...> | ||
|
||
.. _`twig-reference-form-variables`: | ||
|
||
More about Form Variables | ||
|
@@ -295,47 +313,66 @@ object: | |
<?php echo $view['form']->get('name')->vars['label'] ?> | ||
</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 | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd terminate the last two sentences with full stops. Otherwise, to me it feels odd when reading the whole paragraph. |
||
+------------------------+-------------------------------------------------------------------------------------+ | ||
| ``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 | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
+------------------------+-------------------------------------------------------------------------------------+ | ||
| ``data`` | The normalized data of the type | | ||
+------------------------+-------------------------------------------------------------------------------------+ | ||
| ``method`` | The method of the current form (POST, GET, etc) | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. etc. |
||
+------------------------+-------------------------------------------------------------------------------------+ | ||
| ``action`` | The action of the current form (POST, GET, etc) | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually this description is just plain wrong :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, indeed. :) |
||
+------------------------+-------------------------------------------------------------------------------------+ | ||
|
||
.. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig | ||
.. _`the Twig documentation`: http://twig.sensiolabs.org/doc/templates.html#test-operator |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,3 +156,28 @@ These options inherit from the :doc:`form </reference/forms/types/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 selected value(s) | ||
and returns whether the choice is in the selected value(s). | ||
empty_value_in_choices ``Boolean`` Whether the empty value is in the choice list. | ||
====================== ============ ================================================================ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any specific reason to use the different table types? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's wrong to use it here, need to change that. I prefer to use this style, but when using multiline cells, I fallback to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yeah, I remember @webmozart explaining this on his bc promise pull request. Thanks. |
||
|
||
.. tip:: | ||
|
||
It's significantly faster to use the :ref:`form-twig-selectedchoice` test | ||
instead when using Twig. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,3 +100,12 @@ These options inherit from the :doc:`form </reference/forms/types/form>` type: | |
.. include:: /reference/forms/types/options/error_mapping.rst.inc | ||
|
||
.. include:: /reference/forms/types/options/mapped.rst.inc | ||
|
||
Form Variables | ||
-------------- | ||
|
||
======== ========== ========================================================================== | ||
Variable Type Usage | ||
======== ========== ========================================================================== | ||
type ``string`` The type variable is set to ``file``, in order to render like a file input | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [...] in order to render the form type as a file input field |
||
======== ========== ========================================================================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put FormView into literals or maybe use an api link here