Skip to content

Commit

Permalink
Fix for symfony#2425 Bug with empty placeholders
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Matthieu Renard committed Dec 5, 2024
1 parent 92de787 commit 7ea2d64
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/LiveComponent/src/ComponentWithFormTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private function extractFormValues(FormView $formView): array
&& $child->vars['required']
&& !$child->vars['disabled']
&& !$child->vars['value']
&& !$child->vars['placeholder']
&& ($child->vars['placeholder'] === false || $child->vars['placeholder'] === null)
&& !$child->vars['multiple']
&& !$child->vars['expanded']
&& $child->vars['choices']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
],
'placeholder' => 'foo',
])
->add('choice_required_with_empty_placeholder', ChoiceType::class, [
'choices' => [
'bar' => 2,
'foo' => 1,
],
'placeholder' => '',
])
->add('choice_required_without_placeholder', ChoiceType::class, [
'choices' => [
'bar' => 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public function testHandleCheckboxChanges(): void
'range' => '',
'choice' => '',
'choice_required_with_placeholder' => '',
'choice_required_with_empty_placeholder' => '',
'choice_required_without_placeholder' => '2',
'choice_expanded' => '',
'choice_multiple' => ['2'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function testFormValues(): void
'range' => '',
'choice' => '',
'choice_required_with_placeholder' => '',
'choice_required_with_empty_placeholder' => '',
'choice_required_without_placeholder' => '2',
'choice_expanded' => '',
'choice_multiple' => ['2'],
Expand Down

0 comments on commit 7ea2d64

Please sign in to comment.