From a6b7ac421b06b9a8ed3e76a5fb6f47864dc0def3 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Mon, 29 Aug 2022 14:32:12 +1200 Subject: [PATCH] fix: include empty keys --- src/EditableKeyValueField.php | 13 +++++-------- src/SubmittedKeyValueField.php | 1 - 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/EditableKeyValueField.php b/src/EditableKeyValueField.php index 0748949..99fe2b3 100644 --- a/src/EditableKeyValueField.php +++ b/src/EditableKeyValueField.php @@ -48,17 +48,14 @@ public function getFormField() public function getValueFromData($data) { - $incoming = isset($data[$this->Name]) ? $data[$this->Name] : false; - - if (!$incoming) { - return json_encode([]); - } - + $incoming = isset($data[$this->Name]) ? $data[$this->Name] : []; $value = []; foreach ($this->getKeysAsArray() as $i => $k) { - if (isset($data[$i])) { - $value[$k] = $data[$i]; + if (isset($incoming[$i])) { + $value[$k] = $incoming[$i]; + } else { + $value[$k] = ''; } } diff --git a/src/SubmittedKeyValueField.php b/src/SubmittedKeyValueField.php index 1cbdb88..120894d 100644 --- a/src/SubmittedKeyValueField.php +++ b/src/SubmittedKeyValueField.php @@ -9,7 +9,6 @@ class SubmittedKeyValueFormField extends SubmittedFormField { private static $table_name = 'SubmittedKeyValueFormField'; - public function getFormattedValue() { $data = json_decode($this->Value, true);