Skip to content

Commit 3965302

Browse files
Matthieu RenardKocal
Matthieu Renard
authored andcommitted
[LiveComponent] Handle loose comparison with empty placeholder
1 parent 92de787 commit 3965302

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

src/LiveComponent/src/ComponentWithFormTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ private function extractFormValues(FormView $formView): array
265265
&& $child->vars['required']
266266
&& !$child->vars['disabled']
267267
&& !$child->vars['value']
268-
&& !$child->vars['placeholder']
268+
&& (false === $child->vars['placeholder'] || null === $child->vars['placeholder'])
269269
&& !$child->vars['multiple']
270270
&& !$child->vars['expanded']
271271
&& $child->vars['choices']

src/LiveComponent/tests/Fixtures/Form/FormWithManyDifferentFieldsType.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5252
],
5353
'placeholder' => 'foo',
5454
])
55+
->add('choice_required_with_empty_placeholder', ChoiceType::class, [
56+
'choices' => [
57+
'bar' => 2,
58+
'foo' => 1,
59+
],
60+
'placeholder' => '',
61+
])
5562
->add('choice_required_without_placeholder', ChoiceType::class, [
5663
'choices' => [
5764
'bar' => 2,

src/LiveComponent/tests/Functional/Form/ComponentWithFormTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public function testHandleCheckboxChanges(): void
179179
'range' => '',
180180
'choice' => '',
181181
'choice_required_with_placeholder' => '',
182+
'choice_required_with_empty_placeholder' => '',
182183
'choice_required_without_placeholder' => '2',
183184
'choice_expanded' => '',
184185
'choice_multiple' => ['2'],

src/LiveComponent/tests/Unit/Form/ComponentWithFormTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function testFormValues(): void
4444
'range' => '',
4545
'choice' => '',
4646
'choice_required_with_placeholder' => '',
47+
'choice_required_with_empty_placeholder' => '',
4748
'choice_required_without_placeholder' => '2',
4849
'choice_expanded' => '',
4950
'choice_multiple' => ['2'],

0 commit comments

Comments
 (0)