From 7850bc7e04039c9be0e1498a1e25c869e2370b16 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Fri, 25 Mar 2022 10:52:16 +1300 Subject: [PATCH] fix: loading saved data from sessionData --- src/ManyField.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/ManyField.php b/src/ManyField.php index 6089dd4..b3d8c09 100644 --- a/src/ManyField.php +++ b/src/ManyField.php @@ -588,7 +588,8 @@ public function FieldList() { if ($this->value) { foreach ($this->value as $record) { - $output->push($this->generateRow($index++, $record)); + $row = $this->generateRow($index++, $record); + $output->push($row); } } else { // display one if none exist. @@ -655,13 +656,28 @@ public function generateRow($index, $value = null, $prefixName = true) foreach ($this->manyChildren as $child) { $field = clone $child; + $originalName = $field->name; $field = $this->updateManyNestedField($field, $index, $value, $prefixName); $field = $field->setReadonly($this->readonly); $field = $field->setDisabled($this->readonly); - if ($value && is_object($value) && $value->hasMethod('modifyManyRecordField')) { - $field = $value->modifyManyRecordField($field); + if ($value) { + if (is_object($value) && $value->hasMethod('modifyManyRecordField')) { + $field = $value->modifyManyRecordField($field); + } else { + $value = $this->value; + + if (is_object($value)) { + $field = $field->setValue($value->{$field->name}, $value); + } else if (is_array($value)) { + if (isset($value[$originalName])) { + $field = $field->setValue((isset($value[$originalName][$index])) ? $value[$originalName][$index] : null); + } elseif (isset($value[$index][$originalName])) { + $field = $field->setValue((isset($value[$index][$originalName])) ? $value[$index][$originalName] : null); + } + } + } } if ($field) {