Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

Commit 44aafa1

Browse files
committed
Fix for #64
1 parent 2606901 commit 44aafa1

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/Components/FormRadio.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(
2727

2828
$inputName = static::convertBracketsToDots($name);
2929

30-
if (old($inputName)) {
30+
if (old($inputName) !== null) {
3131
$this->checked = old($inputName) == $value;
3232
}
3333

tests/Feature/RadioTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,20 @@ public function it_does_check_the_right_input_element_after_a_validation_error()
4242
->seeElement('input[value="a"]:not(:checked)')
4343
->seeElement('input[value="b"]:checked');
4444
}
45+
46+
/** @test */
47+
public function it_does_check_the_right_input_element_after_a_validation_error_of_another_field()
48+
{
49+
$this->registerTestRoute('radio-with-zero-value', function (Request $request) {
50+
$data = $request->validate([
51+
'input' => 'required',
52+
]);
53+
});
54+
55+
$this->visit('/radio-with-zero-value')
56+
->select('0', 'radio')
57+
->press('Submit')
58+
->seeElement('input[value="0"]:checked')
59+
->seeElement('input[value="1"]:not(:checked)');
60+
}
4561
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<x-form>
2+
<x-form-input name="input" />
3+
4+
<x-form-group>
5+
<x-form-radio name="radio" value="0" />
6+
<x-form-radio name="radio" value="1" />
7+
</x-form-group>
8+
9+
<x-form-submit />
10+
</x-form>

0 commit comments

Comments
 (0)