Skip to content

Commit e9403a6

Browse files
committed
bug #2627 [LiveComponent] Fix default option extraction ignores Translatable #2621 (stehled)
This PR was merged into the 2.x branch. Discussion ---------- [LiveComponent] Fix default option extraction ignores Translatable #2621 | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Issues | Fix #2621 | License | MIT Select placeholder in LiveForm will now accept `string` and `TranslatableInterface` from `symfony/translation-contracts`. Therefore mimicking of default browser behaviour will not happen for `TranslatableInterface`. Commits ------- d36b98e [LiveComponent] `ComponentWithFormTrait` now correctly checks for a `TranslatableInterface` placeholder for `<select>` elements, close #2621
2 parents 9d42463 + d36b98e commit e9403a6

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/LiveComponent/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 2.25.0
44

55
- Add support for [Symfony UID](https://symfony.com/doc/current/components/uid.html) hydration/dehydration
6+
- `ComponentWithFormTrait` now correctly checks for a `TranslatableInterface` placeholder for `<select>` elements
67

78
## 2.23.0
89

src/LiveComponent/src/ComponentWithFormTrait.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Form\FormInterface;
1717
use Symfony\Component\Form\FormView;
1818
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
19+
use Symfony\Contracts\Translation\TranslatableInterface;
1920
use Symfony\UX\LiveComponent\Attribute\LiveProp;
2021
use Symfony\UX\LiveComponent\Attribute\PreReRender;
2122
use Symfony\UX\LiveComponent\Util\LiveFormUtility;
@@ -286,7 +287,8 @@ private function extractFormValues(FormView $formView): array
286287
)
287288
&& !$child->vars['expanded'] // is a <select> (not a radio/checkbox)
288289
&& !$child->vars['multiple'] // is not multiple
289-
&& !\is_string($child->vars['placeholder']) // has no placeholder (empty string is valid)
290+
&& !\is_string($child->vars['placeholder']) // has no placeholder (empty string is valid)
291+
&& !$child->vars['placeholder'] instanceof TranslatableInterface // has no placeholder (translatable interface is valid)
290292
) {
291293
$choices = $child->vars['preferred_choices'] ?: $child->vars['choices']; // preferred_choices has precedence, as they rendered before regular choices
292294
do {

0 commit comments

Comments
 (0)