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

[LiveComponents] Bug with required select with empty placeholders #2425

Closed
FoxCie opened this issue Dec 4, 2024 · 0 comments · Fixed by #2426
Closed

[LiveComponents] Bug with required select with empty placeholders #2425

FoxCie opened this issue Dec 4, 2024 · 0 comments · Fixed by #2426
Labels
Bug Bug Fix Status: Needs Review Needs to be reviewed

Comments

@FoxCie
Copy link

FoxCie commented Dec 4, 2024

Hello,
the last version (2.22.0) fixed bug #1332 that selects the first value of select fields when they are required. This works great, even with placeholders, as they are selected if present, which is the intended behaviour. Unfortunately, due to loose comparison, if there is an empty placeholder (that is, a placeholder defined as the empty string), it is detected as a field without placeholder.

The error comes from the line here :

&& !$child->vars['placeholder']
with :

!$child->vars['placeholder']

Casting the placeholder to a boolean leads to the empty string being considered as an absence of placeholder, this should be tested this way I think :

$child['placeholder'] === null

To reproduce the bug, try a ChoiceType field that is required, with an empty placeholder (['placeholder => ''] in the options array of the form), and see that it takes the first value when changing another field of the form.

Not a big deal, but I had to investigate why the behaviour was different in the previous version, so I might not be the only one.

@FoxCie FoxCie added the Bug Bug Fix label Dec 4, 2024
@carsonbot carsonbot added the Status: Needs Review Needs to be reviewed label Dec 4, 2024
FoxCie pushed a commit to FoxCie/symfony_ux that referenced this issue Dec 5, 2024
Fix for a bug that arises when using an empty placeholder in a required select field, that is wrongly treated as an absence of placeholder by LiveComponents.
@Kocal Kocal closed this as completed in 6008eed Dec 7, 2024
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.

2 participants