|
| 1 | +.. index:: |
| 2 | + single: Forms; Fields; WeekType |
| 3 | + |
| 4 | +WeekType Field |
| 5 | +============== |
| 6 | + |
| 7 | +.. versionadded:: 4.4 |
| 8 | + |
| 9 | + The ``WeekType`` type was introduced in Symfony 4.4. |
| 10 | + |
| 11 | +This field type allows the user to modify data that represents a specific |
| 12 | +`ISO 8601`_ week number (e.g. ``1984-W05``). |
| 13 | + |
| 14 | +Can be rendered as a text input or select tags. The underlying format of |
| 15 | +the data can be a string or an array. |
| 16 | + |
| 17 | ++----------------------+-----------------------------------------------------------------------------+ |
| 18 | +| Underlying Data Type | can be a string, or array (see the ``input`` option) | |
| 19 | ++----------------------+-----------------------------------------------------------------------------+ |
| 20 | +| Rendered as | single text box, two text boxes or two select fields | |
| 21 | ++----------------------+-----------------------------------------------------------------------------+ |
| 22 | +| Options | - `choice_translation_domain`_ | |
| 23 | +| | - `placeholder`_ | |
| 24 | +| | - `html5`_ | |
| 25 | +| | - `input`_ | |
| 26 | +| | - `widget`_ | |
| 27 | +| | - `weeks`_ | |
| 28 | +| | - `years`_ | |
| 29 | ++----------------------+-----------------------------------------------------------------------------+ |
| 30 | +| Overridden options | - `compound`_ | |
| 31 | +| | - `empty_data`_ | |
| 32 | +| | - `error_bubbling`_ | |
| 33 | ++----------------------+-----------------------------------------------------------------------------+ |
| 34 | +| Inherited | - `attr`_ | |
| 35 | +| options | - `data`_ | |
| 36 | +| | - `disabled`_ | |
| 37 | +| | - `help`_ | |
| 38 | +| | - `help_attr`_ | |
| 39 | +| | - `help_html`_ | |
| 40 | +| | - `inherit_data`_ | |
| 41 | +| | - `invalid_message`_ | |
| 42 | +| | - `invalid_message_parameters`_ | |
| 43 | +| | - `mapped`_ | |
| 44 | +| | - `row_attr`_ | |
| 45 | ++----------------------+-----------------------------------------------------------------------------+ |
| 46 | +| Parent type | :doc:`FormType </reference/forms/types/form>` | |
| 47 | ++----------------------+-----------------------------------------------------------------------------+ |
| 48 | +| Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\WeekType` | |
| 49 | ++----------------------+-----------------------------------------------------------------------------+ |
| 50 | + |
| 51 | +.. include:: /reference/forms/types/options/_debug_form.rst.inc |
| 52 | + |
| 53 | +Field Options |
| 54 | +------------- |
| 55 | + |
| 56 | +.. include:: /reference/forms/types/options/choice_translation_domain.rst.inc |
| 57 | + |
| 58 | +placeholder |
| 59 | +~~~~~~~~~~~ |
| 60 | + |
| 61 | +**type**: ``string`` | ``array`` |
| 62 | + |
| 63 | +If your widget option is set to ``choice``, then this field will be represented |
| 64 | +as a series of ``select`` boxes. When the placeholder value is a string, |
| 65 | +it will be used as the **blank value** of all select boxes:: |
| 66 | + |
| 67 | + use Symfony\Component\Form\Extension\Core\Type\WeekType; |
| 68 | + |
| 69 | + $builder->add('startWeek', WeekType::class, [ |
| 70 | + 'placeholder' => 'Select a value', |
| 71 | + ]); |
| 72 | + |
| 73 | +Alternatively, you can use an array that configures different placeholder |
| 74 | +values for the year and week fields:: |
| 75 | + |
| 76 | + use Symfony\Component\Form\Extension\Core\Type\WeekType; |
| 77 | + |
| 78 | + $builder->add('startDateTime', WeekType::class, [ |
| 79 | + 'placeholder' => [ |
| 80 | + 'year' => 'Year', 'week' => 'Week', |
| 81 | + ] |
| 82 | + ]); |
| 83 | + |
| 84 | + |
| 85 | +.. include:: /reference/forms/types/options/html5.rst.inc |
| 86 | + |
| 87 | +input |
| 88 | +~~~~~ |
| 89 | + |
| 90 | +**type**: ``string`` **default**: ``array`` |
| 91 | + |
| 92 | +The format of the *input* data - i.e. the format that the date is stored |
| 93 | +on your underlying object. Valid values are: |
| 94 | + |
| 95 | +* ``string`` (e.g. ``2011-W17``) |
| 96 | +* ``array`` (e.g. ``[2011, 17]``) |
| 97 | + |
| 98 | +The value that comes back from the form will also be normalized back into |
| 99 | +this format. |
| 100 | + |
| 101 | +widget |
| 102 | +~~~~~~ |
| 103 | + |
| 104 | +**type**: ``string`` **default**: ``choice`` |
| 105 | + |
| 106 | +The basic way in which this field should be rendered. Can be one of the |
| 107 | +following: |
| 108 | + |
| 109 | +* ``choice``: renders two select inputs. |
| 110 | + |
| 111 | +* ``text``: renders a two field input of type ``text`` (year, week). |
| 112 | + |
| 113 | +* ``single_text``: renders a single input of type ``week``. |
| 114 | + |
| 115 | +years |
| 116 | +~~~~~ |
| 117 | + |
| 118 | +**type**: ``array`` **default**: ten years before to ten years after the |
| 119 | +current year |
| 120 | + |
| 121 | +List of years available to the year field type. This option is only relevant |
| 122 | +when the ``widget`` option is set to ``choice``. |
| 123 | + |
| 124 | + |
| 125 | +.. include:: /reference/forms/types/options/weeks.rst.inc |
| 126 | + |
| 127 | +Overridden Options |
| 128 | +------------------ |
| 129 | + |
| 130 | +.. include:: /reference/forms/types/options/compound_type.rst.inc |
| 131 | + |
| 132 | +.. include:: /reference/forms/types/options/empty_data.rst.inc |
| 133 | + :end-before: DEFAULT_PLACEHOLDER |
| 134 | + |
| 135 | +The actual default value of this option depends on other field options: |
| 136 | + |
| 137 | +* If ``widget`` is ``single_text``, then ``''`` |
| 138 | + (empty string); |
| 139 | +* Otherwise ``[]`` (empty array). |
| 140 | + |
| 141 | +.. include:: /reference/forms/types/options/empty_data.rst.inc |
| 142 | + :start-after: DEFAULT_PLACEHOLDER |
| 143 | + |
| 144 | +error_bubbling |
| 145 | +~~~~~~~~~~~~~~ |
| 146 | + |
| 147 | +**default**: ``false`` |
| 148 | + |
| 149 | +Inherited Options |
| 150 | +----------------- |
| 151 | + |
| 152 | +These options inherit from the :doc:`FormType </reference/forms/types/form>`: |
| 153 | + |
| 154 | +.. include:: /reference/forms/types/options/attr.rst.inc |
| 155 | + |
| 156 | +.. include:: /reference/forms/types/options/data.rst.inc |
| 157 | + |
| 158 | +.. include:: /reference/forms/types/options/disabled.rst.inc |
| 159 | + |
| 160 | +.. include:: /reference/forms/types/options/help.rst.inc |
| 161 | + |
| 162 | +.. include:: /reference/forms/types/options/help_attr.rst.inc |
| 163 | + |
| 164 | +.. include:: /reference/forms/types/options/help_html.rst.inc |
| 165 | + |
| 166 | +.. include:: /reference/forms/types/options/inherit_data.rst.inc |
| 167 | + |
| 168 | +.. include:: /reference/forms/types/options/invalid_message.rst.inc |
| 169 | + |
| 170 | +.. include:: /reference/forms/types/options/invalid_message_parameters.rst.inc |
| 171 | + |
| 172 | +.. include:: /reference/forms/types/options/mapped.rst.inc |
| 173 | + |
| 174 | +.. include:: /reference/forms/types/options/row_attr.rst.inc |
| 175 | + |
| 176 | +Field Variables |
| 177 | +--------------- |
| 178 | + |
| 179 | ++----------+------------+----------------------------------------------------------------------+ |
| 180 | +| Variable | Type | Usage | |
| 181 | ++==========+============+======================================================================+ |
| 182 | +| widget | ``mixed`` | The value of the `widget`_ option. | |
| 183 | ++----------+------------+----------------------------------------------------------------------+ |
| 184 | +| type | ``string`` | Only present when widget is ``single_text`` and HTML5 is activated, | |
| 185 | +| | | contains the input type to use (``datetime``, ``date`` or ``time``). | |
| 186 | ++----------+------------+----------------------------------------------------------------------+ |
| 187 | + |
| 188 | +.. _`ISO 8601`: https://en.wikipedia.org/wiki/ISO_8601 |
0 commit comments