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

Commit a008d1f

Browse files
committed
Fix for #58
1 parent 44aafa1 commit a008d1f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/Components/HandlesDefaultAndOldValue.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ private function setValue(
1919
$inputName = static::convertBracketsToDots($name);
2020

2121
if (!$language) {
22-
$default = $this->getBoundValue($bind, $name) ?: $default;
22+
$boundValue = $this->getBoundValue($bind, $name);
23+
24+
$default = is_null($boundValue) ? $default : $boundValue;
2325

2426
return $this->value = old($inputName, $default);
2527
}

tests/Feature/BindTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ public function it_can_bind_a_target_to_the_form()
2323
->seeElement('input[name="radio"]:checked');
2424
}
2525

26+
/** @test */
27+
public function it_sets_the_right_value_if_the_value_is_zero()
28+
{
29+
$this->registerTestRoute('bind-target-zero-value');
30+
31+
$this->visit('/bind-target-zero-value')
32+
->seeElement('input[name="input"][value="0"]');
33+
}
34+
2635
/** @test */
2736
public function it_overrides_the_bound_target_with_the_old_request_data()
2837
{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@php
2+
$target = [
3+
'input' => 0,
4+
];
5+
@endphp
6+
7+
<x-form>
8+
@bind($target)
9+
<x-form-input name="input" />
10+
<x-form-submit />
11+
@endbind
12+
</x-form>

0 commit comments

Comments
 (0)