Skip to content

Commit

Permalink
Fixed: If 'select' key is indecies, lost 'selected' attribute. Added …
Browse files Browse the repository at this point in the history
…unit test (#2769)

* Fixed: If 'select' value is number, lost 'selected' attribute
  • Loading branch information
lihe6666 authored Dec 18, 2023
1 parent 9373e75 commit 78f56fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resources/views/fields/select.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@isset($value)
@if (is_array($value) && in_array($key, $value)) selected
@elseif (isset($value[$key]) && $value[$key] == $option) selected
@elseif (!$isOptionList && $key == $value) selected
@elseif (is_string($value) && $key == $value) selected
@endif
@endisset
>{{$option}}</option>
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/Screen/Fields/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ public function testSetValue(): void
$this->assertStringContainsString('value="second" selected', $view);
}

public function testSetIndicesValue(): void
{
$select = Select::make('Indices')
->value('1')
->options([
'0' => 'First Value',
'1' => 'Second Value',
'2' => 'Third Value'
]);

$view = self::minifyRenderField($select);

$this->assertStringContainsString('value="1" selected', $view);
}

public function testAutoFocus(): void
{
$select = Select::make('about')
Expand Down

0 comments on commit 78f56fd

Please sign in to comment.