Skip to content
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

[LiveForm] Required select with placeholder of TranslatableMessage has first value set upon rerender #2621

Open
stehled opened this issue Mar 3, 2025 · 2 comments · May be fixed by #2627
Open
Labels
Bug Bug Fix Status: Needs Review Needs to be reviewed

Comments

@stehled
Copy link

stehled commented Mar 3, 2025

The bug:
While having a liveform with required select and placeholder of type TranslatableMessage, instead of leaving this value blank, first not null value from choices is retrieved instead.

This behaviour occurs because of code in Symfony\UX\LiveComponent\ComponentWithFormTrait in if on line 276.

.

In this if, the last condition is !\is_string($child->vars['placeholder']) which unfortunately is not satisfied e.g. for option 'placeholder' => new TranslatableMessage('some.value').

Solution
I would suggest to extending this condition to (!\is_string($child->vars['placeholder']) && !$child->vars['placeholder'] instanceof TranslatableMessage) or making it only !isset($child->vars['placeholder']) to support more cases. I feel that string only restriction is to harsh when most of the time, we will be creating multilingual applications.

We use TranslatableMessage class for translatable strings so our extractor can generate .yaml files with translations.

@stehled stehled added the Bug Bug Fix label Mar 3, 2025
@carsonbot carsonbot added the Status: Needs Review Needs to be reviewed label Mar 3, 2025
@smnandre
Copy link
Member

smnandre commented Mar 5, 2025

I would suggest to extending this condition to (!\is_string($child->vars['placeholder']) && !$child->vars['placeholder'] instanceof TranslatableMessage)

Would you like to open a PR ?

or making it only !isset($child->vars['placeholder']) to support more cases

Any example of such case ?

@stehled
Copy link
Author

stehled commented Mar 5, 2025

Hi, thanks for reply, I will create PR tomorrow.

I was not able to think of any other case, therefore I will use the first suggested solution.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants