Skip to content

Commit

Permalink
fix: include empty keys
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Aug 29, 2022
1 parent 3dc1f35 commit a6b7ac4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
13 changes: 5 additions & 8 deletions src/EditableKeyValueField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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] = '';
}
}

Expand Down
1 change: 0 additions & 1 deletion src/SubmittedKeyValueField.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class SubmittedKeyValueFormField extends SubmittedFormField
{
private static $table_name = 'SubmittedKeyValueFormField';


public function getFormattedValue()
{
$data = json_decode($this->Value, true);
Expand Down

0 comments on commit a6b7ac4

Please sign in to comment.