Skip to content

Commit

Permalink
Form // fixing bug where non-existing fields in data array caused to …
Browse files Browse the repository at this point in the history
…overwrite existing field values (defaults) with empty values.
  • Loading branch information
Chrico committed Sep 11, 2023
1 parent fbc016f commit 9cf5907
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Element/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ public function withData(array $data = []): static
throw new LogicException('You cannot change data of a submitted form.');
}

foreach ($this->elements() as $name => $element) {
$value = $data[$name] ?? '';
$this->rawData[$name] = $value;

foreach ($data as $name => $value) {
if (!$this->elementExists($name)) {
continue;
}
$element = $this->element($name);
$element->withValue($value);
$this->data[$name] = $element->value();
}
Expand Down

0 comments on commit 9cf5907

Please sign in to comment.