Skip to content

Commit 6b37e58

Browse files
authored
Fix issue that would cause validation errors to be reset (#102)
1 parent 030b55d commit 6b37e58

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Livewire/Concerns/WithFields.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,21 @@ public function mountedFields(Collection $fields): void
3131

3232
public function updatedFields(mixed $value, string $key): void
3333
{
34-
$this->validateOnly("fields.{$key}");
34+
/**
35+
* When handling array fields like checkboxes, the $key can look like "services.value.0".
36+
* This can cause issues with validation, since it targets a specific item instead of the whole array.
37+
* The following code fixes this by pointing the $key to the full array "services.value" instead.
38+
*/
39+
$key = str($key)->explode('.')->slice(0, 2)->prepend('fields')->join('.');
40+
41+
$this->validateOnly($key);
3542

3643
/**
3744
* Explicitly forget the errors of this field after validation has passed
3845
* so that we don't restore them in some edge case scenarios.
3946
*/
4047
if ($this->isWizardForm()) {
41-
$this->resetStepErrorBag("fields.{$key}");
48+
$this->resetStepErrorBag($key);
4249
}
4350
}
4451

0 commit comments

Comments
 (0)