Skip to content

Commit

Permalink
Fix default field value (#69)
Browse files Browse the repository at this point in the history
Co-authored-by: Yanick Witschi <[email protected]>
  • Loading branch information
wiphi and Toflar authored Feb 16, 2023
1 parent aed09d6 commit 0c72e32
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/EventListener/LoadFormFieldListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ public function __invoke(Widget $widget, string $formId, array $formData, Form $
// We only prefill the value if it was not submitted in this step.
// If you submit a value in step 1, go to step 2, then go back to step 1 and submit a wrong value there, Contao
// would display an error, but we'd prefill it again with the previous value which would make no sense.
// Moreover, we prefill with submitted data as priority (= validated submitted widget data) and otherwise fall
// back to potential previous post data which has not been validated yet (e.g. you filled in the values on step 2
// but then navigated back)
// We prefill in the following order:
// 1. Submitted data (= validated submitted widget data)
// 2. Fall back to potentially previously post data which has not been validated yet (e.g. you filled in the values
// on step 2 but then navigated back)
// 3. The widget default value itself
if (!$postData->has($widget->name)) {
$widget->value = $stepData->getSubmitted()->get($widget->name, $stepData->getOriginalPostData()->get($widget->name));
$widget->value = $stepData->getSubmitted()->get(
$widget->name, $stepData->getOriginalPostData()->get($widget->name, $widget->value)
);
}

return $widget;
Expand Down

0 comments on commit 0c72e32

Please sign in to comment.