From 8fcd394faf71e578a2c9e7c5eb5a54cc75eceff2 Mon Sep 17 00:00:00 2001 From: Jordane Vaspard Date: Sat, 26 Nov 2022 18:01:00 +0100 Subject: [PATCH] Add a placeholder_attr option to ChoiceType --- reference/forms/types/choice.rst | 4 ++++ reference/forms/types/country.rst | 2 ++ reference/forms/types/currency.rst | 2 ++ reference/forms/types/entity.rst | 2 ++ reference/forms/types/enum.rst | 2 ++ reference/forms/types/language.rst | 2 ++ reference/forms/types/locale.rst | 2 ++ .../types/options/placeholder_attr.rst.inc | 21 +++++++++++++++++++ reference/forms/types/timezone.rst | 2 ++ 9 files changed, 39 insertions(+) create mode 100644 reference/forms/types/options/placeholder_attr.rst.inc diff --git a/reference/forms/types/choice.rst b/reference/forms/types/choice.rst index 9d2ade8df4c..154386c4ffb 100644 --- a/reference/forms/types/choice.rst +++ b/reference/forms/types/choice.rst @@ -212,6 +212,8 @@ the ``Choice`` constraint behave like a ``NotChoice`` constraint. .. include:: /reference/forms/types/options/placeholder.rst.inc +.. include:: /reference/forms/types/options/placeholder_attr.rst.inc + .. include:: /reference/forms/types/options/preferred_choices.rst.inc Overridden Options @@ -311,6 +313,8 @@ Field Variables | placeholder | ``mixed`` | The empty value if not already in the list, otherwise | | | | ``null``. | +----------------------------+--------------+-------------------------------------------------------------------+ +| placeholder_attr | ``array`` | The value of the `placeholder_attr`_ option. | ++----------------------------+--------------+-------------------------------------------------------------------+ | choice_translation_domain | ``mixed`` | ``boolean``, ``null`` or ``string`` to determine if the value | | | | should be translated. | +----------------------------+--------------+-------------------------------------------------------------------+ diff --git a/reference/forms/types/country.rst b/reference/forms/types/country.rst index 4362cefd0d0..8c6e1bf20f9 100644 --- a/reference/forms/types/country.rst +++ b/reference/forms/types/country.rst @@ -81,6 +81,8 @@ These options inherit from the :doc:`ChoiceType ` .. include:: /reference/forms/types/options/placeholder.rst.inc +.. include:: /reference/forms/types/options/placeholder_attr.rst.inc + .. include:: /reference/forms/types/options/preferred_choices.rst.inc .. include:: /reference/forms/types/options/choice_type_trim.rst.inc diff --git a/reference/forms/types/currency.rst b/reference/forms/types/currency.rst index 7ffa36a4f73..a80051022ae 100644 --- a/reference/forms/types/currency.rst +++ b/reference/forms/types/currency.rst @@ -62,6 +62,8 @@ These options inherit from the :doc:`ChoiceType ` .. include:: /reference/forms/types/options/placeholder.rst.inc +.. include:: /reference/forms/types/options/placeholder_attr.rst.inc + .. include:: /reference/forms/types/options/preferred_choices.rst.inc .. include:: /reference/forms/types/options/choice_type_trim.rst.inc diff --git a/reference/forms/types/entity.rst b/reference/forms/types/entity.rst index 721a503aae2..80712a98c75 100644 --- a/reference/forms/types/entity.rst +++ b/reference/forms/types/entity.rst @@ -256,6 +256,8 @@ Doctrine's Array Collection. .. include:: /reference/forms/types/options/placeholder.rst.inc +.. include:: /reference/forms/types/options/placeholder_attr.rst.inc + ``preferred_choices`` ~~~~~~~~~~~~~~~~~~~~~ diff --git a/reference/forms/types/enum.rst b/reference/forms/types/enum.rst index 4ee2559f70b..f5c1378dc89 100644 --- a/reference/forms/types/enum.rst +++ b/reference/forms/types/enum.rst @@ -78,6 +78,8 @@ These options inherit from the :doc:`ChoiceType ` .. include:: /reference/forms/types/options/placeholder.rst.inc +.. include:: /reference/forms/types/options/placeholder_attr.rst.inc + .. include:: /reference/forms/types/options/preferred_choices.rst.inc .. include:: /reference/forms/types/options/choice_type_trim.rst.inc diff --git a/reference/forms/types/language.rst b/reference/forms/types/language.rst index a29ef50930d..b00aa6af6d9 100644 --- a/reference/forms/types/language.rst +++ b/reference/forms/types/language.rst @@ -98,6 +98,8 @@ These options inherit from the :doc:`ChoiceType ` .. include:: /reference/forms/types/options/placeholder.rst.inc +.. include:: /reference/forms/types/options/placeholder_attr.rst.inc + .. include:: /reference/forms/types/options/preferred_choices.rst.inc .. include:: /reference/forms/types/options/choice_type_trim.rst.inc diff --git a/reference/forms/types/locale.rst b/reference/forms/types/locale.rst index 4ee77116489..dae2d26cb87 100644 --- a/reference/forms/types/locale.rst +++ b/reference/forms/types/locale.rst @@ -75,6 +75,8 @@ These options inherit from the :doc:`ChoiceType ` .. include:: /reference/forms/types/options/placeholder.rst.inc +.. include:: /reference/forms/types/options/placeholder_attr.rst.inc + .. include:: /reference/forms/types/options/preferred_choices.rst.inc .. include:: /reference/forms/types/options/choice_type_trim.rst.inc diff --git a/reference/forms/types/options/placeholder_attr.rst.inc b/reference/forms/types/options/placeholder_attr.rst.inc new file mode 100644 index 00000000000..49b656cc6df --- /dev/null +++ b/reference/forms/types/options/placeholder_attr.rst.inc @@ -0,0 +1,21 @@ +``placeholder_attr`` +~~~~~~~~~~~~~~~~~~~~ + +**type**: ``array`` **default**: ``[]`` + +Use this to add additional HTML attributes to the placeholder choice:: + + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('fruits', ChoiceType::class, [ + // ... + 'placeholder' => '...', + 'placeholder_attr' => [ + ['title' => 'Choose an option'], + ], + ]); + +.. versionadded:: 6.3 + + The ``placeholder_attr`` option was introduced in Symfony 6.3. diff --git a/reference/forms/types/timezone.rst b/reference/forms/types/timezone.rst index 6dc0d793b3b..270d44bf281 100644 --- a/reference/forms/types/timezone.rst +++ b/reference/forms/types/timezone.rst @@ -92,6 +92,8 @@ These options inherit from the :doc:`ChoiceType ` .. include:: /reference/forms/types/options/placeholder.rst.inc +.. include:: /reference/forms/types/options/placeholder_attr.rst.inc + .. include:: /reference/forms/types/options/preferred_choices.rst.inc .. include:: /reference/forms/types/options/choice_type_trim.rst.inc