Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Forms/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ private function selectDropdown(): Element
{
$elements = [];
foreach ($this->options as $value => $content) {
$value = strval($value);
$option = Element::option($content)->props('value ' . $value);
if ($this->isSelected($value)) {
$option = $option->prop('selected selected');
Expand All @@ -150,6 +151,7 @@ private function selectOther(): Element
$type = 'checkbox';
}
foreach ($this->options as $value => $content) {
$value = strval($value);
$id = $this->name . '-' . $value;
$label = Element::label($content)->props('for ' . $id);
$input = Element::input()->omitEndTag()->props(
Expand Down
21 changes: 21 additions & 0 deletions tests/Forms/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,25 @@ public function is_expected_base(): void // phpcs:ignore

$this->assertSame($expected, $result);
}

/**
* @test
*/
public function error_is_selected_value_always_string(): void // phpcs:ignore
{
$expected = <<<html
<div><label for="select">Select your option</label><select id="select" name="select"><option value="0">display</option></select></div>
html;

// Even with strict types, number-based keys become integers
$result = (string) Select::create(
'Select your option',
'select',
[
'0' => 'display'
]
);

$this->assertSame($expected, $result);
}
}