Skip to content

Commit c6189b4

Browse files
author
Maurice Niedergesäß
committed
Added forceCreate parameter to ComponentWithFormTrait::getFormView() forcing a recreation of the FormView. Invoked only once with true in ComponentWithFormTrait::submitFormOnRender() to synchronize FormView and FormInstance
1 parent 6d2daab commit c6189b4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/LiveComponent/src/ComponentWithFormTrait.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,16 @@ public function submitFormOnRender(): void
111111
if ($this->shouldAutoSubmitForm) {
112112
$this->submitForm($this->isValidated);
113113
}
114+
115+
// Recreate the FormView because it has been created by the submitForm() with a FormInterface whose values may
116+
// have changed. Basically synchronizes FormView and FormInstance to reflect all manual changes made to the
117+
// latter between form submit and the components re-render.
118+
$this->getFormView(true);
114119
}
115120

116-
public function getFormView(): FormView
121+
public function getFormView(bool $forceCreate = false): FormView
117122
{
118-
if (null === $this->formView) {
123+
if ($forceCreate || null === $this->formView) {
119124
$this->formView = $this->getForm()->createView();
120125
$this->useNameAttributesAsModelName();
121126
}

0 commit comments

Comments
 (0)