Skip to content

Add new WeekType Documentation #12584

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 1 commit into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions reference/forms/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Form Types Reference
types/datetime
types/time
types/birthday
types/week

types/checkbox
types/file
Expand Down
1 change: 1 addition & 0 deletions reference/forms/types/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Date and Time Fields
* :doc:`DateTimeType </reference/forms/types/datetime>`
* :doc:`TimeType </reference/forms/types/time>`
* :doc:`BirthdayType </reference/forms/types/birthday>`
* :doc:`WeekType </reference/forms/types/week>`

Other Fields
~~~~~~~~~~~~
Expand Down
7 changes: 7 additions & 0 deletions reference/forms/types/options/weeks.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
weeks
~~~~~

**type**: ``array`` **default**: 1 to 53

List of weeks available to the week field type. This option is only relevant
when the ``widget`` option is set to ``choice``.
188 changes: 188 additions & 0 deletions reference/forms/types/week.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
.. index::
single: Forms; Fields; WeekType

WeekType Field
==============

.. versionadded:: 4.4

The ``WeekType`` type was introduced in Symfony 4.4.

This field type allows the user to modify data that represents a specific
`ISO 8601`_ week number (e.g. ``1984-W05``).

Can be rendered as a text input or select tags. The underlying format of
the data can be a string or an array.

+----------------------+-----------------------------------------------------------------------------+
| Underlying Data Type | can be a string, or array (see the ``input`` option) |
+----------------------+-----------------------------------------------------------------------------+
| Rendered as | single text box, two text boxes or two select fields |
+----------------------+-----------------------------------------------------------------------------+
| Options | - `choice_translation_domain`_ |
| | - `placeholder`_ |
| | - `html5`_ |
| | - `input`_ |
| | - `widget`_ |
| | - `weeks`_ |
| | - `years`_ |
+----------------------+-----------------------------------------------------------------------------+
| Overridden options | - `compound`_ |
| | - `empty_data`_ |
| | - `error_bubbling`_ |
+----------------------+-----------------------------------------------------------------------------+
| Inherited | - `attr`_ |
| options | - `data`_ |
| | - `disabled`_ |
| | - `help`_ |
| | - `help_attr`_ |
| | - `help_html`_ |
| | - `inherit_data`_ |
| | - `invalid_message`_ |
| | - `invalid_message_parameters`_ |
| | - `mapped`_ |
| | - `row_attr`_ |
+----------------------+-----------------------------------------------------------------------------+
| Parent type | :doc:`FormType </reference/forms/types/form>` |
+----------------------+-----------------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\WeekType` |
+----------------------+-----------------------------------------------------------------------------+

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

Field Options
-------------

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

placeholder
~~~~~~~~~~~

**type**: ``string`` | ``array``

If your widget option is set to ``choice``, then this field will be represented
as a series of ``select`` boxes. When the placeholder value is a string,
it will be used as the **blank value** of all select boxes::

use Symfony\Component\Form\Extension\Core\Type\WeekType;

$builder->add('startWeek', WeekType::class, [
'placeholder' => 'Select a value',
]);

Alternatively, you can use an array that configures different placeholder
values for the year and week fields::

use Symfony\Component\Form\Extension\Core\Type\WeekType;

$builder->add('startDateTime', WeekType::class, [
'placeholder' => [
'year' => 'Year', 'week' => 'Week',
]
]);


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

input
~~~~~

**type**: ``string`` **default**: ``array``

The format of the *input* data - i.e. the format that the date is stored
on your underlying object. Valid values are:

* ``string`` (e.g. ``2011-W17``)
* ``array`` (e.g. ``[2011, 17]``)

The value that comes back from the form will also be normalized back into
this format.

widget
~~~~~~

**type**: ``string`` **default**: ``choice``

The basic way in which this field should be rendered. Can be one of the
following:

* ``choice``: renders two select inputs.

* ``text``: renders a two field input of type ``text`` (year, week).

* ``single_text``: renders a single input of type ``week``.

years
~~~~~

**type**: ``array`` **default**: ten years before to ten years after the
current year

List of years available to the year field type. This option is only relevant
when the ``widget`` option is set to ``choice``.


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

Overridden Options
------------------

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

.. include:: /reference/forms/types/options/empty_data.rst.inc
:end-before: DEFAULT_PLACEHOLDER

The actual default value of this option depends on other field options:

* If ``widget`` is ``single_text``, then ``''``
(empty string);
* Otherwise ``[]`` (empty array).

.. include:: /reference/forms/types/options/empty_data.rst.inc
:start-after: DEFAULT_PLACEHOLDER

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

**default**: ``false``

Inherited Options
-----------------

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

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

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

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

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

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

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

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

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

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

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

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

Field Variables
---------------

+----------+------------+----------------------------------------------------------------------+
| Variable | Type | Usage |
+==========+============+======================================================================+
| widget | ``mixed`` | The value of the `widget`_ option. |
+----------+------------+----------------------------------------------------------------------+
| type | ``string`` | Only present when widget is ``single_text`` and HTML5 is activated, |
| | | contains the input type to use (``datetime``, ``date`` or ``time``). |
+----------+------------+----------------------------------------------------------------------+

.. _`ISO 8601`: https://en.wikipedia.org/wiki/ISO_8601