Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #2426 [LiveComponent] Handle loose comparison with empty placehol…
…der (Matthieu Renard) This PR was squashed before being merged into the 2.x branch. Discussion ---------- [LiveComponent] Handle loose comparison with empty placeholder 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. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Issues | Fix #2425 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT LiveComponents test placeholders of required selects to detect when to set a default value from the choices (i.e. if the select is required and does not have a placeholder, among other conditions) by just casting the placeholder to a boolean. This leads to empty placeholders (placeholders that are the empty string) to be treated as an absence of placeholders when they should not. This MR fixes this by replacing the condition on placeholders with a more appropriate one. According to the docs https://symfony.com/doc/current/reference/forms/types/choice.html#placeholder and https://symfony.com/doc/current/reference/forms/types/choice.html#field-variables, the placeholder can be a boolean (`false` indicates that there should not be a placeholder), a string (the text to display for the empty value) or a TranslatableMessage (same as string, but goes through a translator before being displayed). The vars property is either the value of the field, or `null` if there is no placeholder specified. From this, I considered that there is no placeholder either if the placeholder holds `false` or `null`. I added a simple test that checks the behaviour when there is a required select with an empty placeholder ; we expect the value of the field to be empty in such cases when we do not modify it. Commits ------- 3965302 [LiveComponent] Handle loose comparison with empty placeholder
- Loading branch information