Skip to content

Commit

Permalink
Omit certain items from API mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tobimori committed Oct 26, 2024
1 parent e1e2c56 commit a93038f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions classes/Models/FormPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function htmxAttr(Page $page, array $attr): array
'hx-vals' => Json::encode(array_filter([
'dreamform:page' => Htmx::encrypt($page->uuid()->toString()),
'dreamform:attr' => Htmx::encrypt(Json::encode($attr))
], fn ($value) => $value !== null))
], fn($value) => $value !== null))
];

return $htmx;
Expand Down Expand Up @@ -333,7 +333,14 @@ public function render(array $data = [], $contentType = 'html'): string
// if dreamform is used in API mode, return the submission state as JSON
if ($mode === 'api') {
$kirby->response()->code($submission->isSuccessful() ? 200 : 400);
return json_encode(A::merge($submission->state()->toArray(), $this->isMultiStep() ? [
return json_encode(A::merge(array_filter($submission->state()->toArray(), fn($key) => A::has([
'success',
'step',
'redirect',
'error',
'errors',
'actions'
], $key), ARRAY_FILTER_USE_KEY), $this->isMultiStep() ? [
'session' => Htmx::encrypt($submission->slug())
] : []), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT);
}
Expand Down

0 comments on commit a93038f

Please sign in to comment.