Skip to content

Commit 0d158f0

Browse files
committed
bug #7575 Apply DefaultColumns to ChoiceField regardless of widget type (lacatoire)
This PR was submitted for the 5.x branch but it was squashed and merged into the 4.x branch instead. Discussion ---------- Apply DefaultColumns to ChoiceField regardless of widget type When a ChoiceField uses the native `<select>` widget (via `renderAsNativeWidget(true)`), the default columns were never set because the call to `setDefaultColumns()` was nested inside the autocomplete branch, leaving the field with an overly wide layout. Moving the default columns assignment outside that conditional restores the expected column sizing for all widget types, while preserving the existing values for the autocomplete widget. Fixes #7550 Commits ------- 7d4642f Apply DefaultColumns to ChoiceField regardless of widget type
2 parents 70f894d + 7d4642f commit 0d158f0

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/Field/Configurator/ChoiceConfigurator.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c
9494

9595
if (ChoiceField::WIDGET_AUTOCOMPLETE === $field->getCustomOption(ChoiceField::OPTION_WIDGET)) {
9696
$field->setFormTypeOption('attr.data-ea-widget', 'ea-autocomplete');
97-
if ('' === $field->getDefaultColumns()) {
98-
$field->setDefaultColumns($isMultipleChoice ? 'col-md-8 col-xxl-6' : 'col-md-6 col-xxl-5');
99-
}
97+
}
98+
99+
if ('' === $field->getDefaultColumns()) {
100+
$field->setDefaultColumns($isMultipleChoice ? 'col-md-8 col-xxl-6' : 'col-md-6 col-xxl-5');
100101
}
101102

102103
$field->setFormTypeOptionIfNotSet('placeholder', '');

tests/Unit/Field/Configurator/ChoiceConfiguratorTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,39 @@ public function testBackedEnumChoicesLabeled(): void
113113

114114
$this->assertSame($choices, $this->configure($field)->getFormTypeOption('choices'));
115115
}
116+
117+
public function testDefaultColumnsAreAppliedOnAutocompleteWidget(): void
118+
{
119+
$field = ChoiceField::new(self::PROPERTY_NAME);
120+
121+
$this->assertSame('col-md-6 col-xxl-5', $this->configure($field)->getDefaultColumns());
122+
}
123+
124+
public function testDefaultColumnsAreAppliedOnNativeWidget(): void
125+
{
126+
$field = ChoiceField::new(self::PROPERTY_NAME)->renderAsNativeWidget();
127+
128+
$this->assertSame('col-md-6 col-xxl-5', $this->configure($field)->getDefaultColumns());
129+
}
130+
131+
public function testDefaultColumnsAreAppliedOnExpandedWidget(): void
132+
{
133+
$field = ChoiceField::new(self::PROPERTY_NAME)->renderExpanded();
134+
135+
$this->assertSame('col-md-6 col-xxl-5', $this->configure($field)->getDefaultColumns());
136+
}
137+
138+
public function testDefaultColumnsAreWiderOnMultipleNativeWidget(): void
139+
{
140+
$field = ChoiceField::new(self::PROPERTY_NAME)->renderAsNativeWidget()->allowMultipleChoices();
141+
142+
$this->assertSame('col-md-8 col-xxl-6', $this->configure($field)->getDefaultColumns());
143+
}
144+
145+
public function testUserDefinedColumnsAreNotOverridden(): void
146+
{
147+
$field = ChoiceField::new(self::PROPERTY_NAME)->renderAsNativeWidget()->setColumns('col-md-4');
148+
149+
$this->assertSame('col-md-4', $this->configure($field)->getColumns());
150+
}
116151
}

0 commit comments

Comments
 (0)