From 2ed4abfd2eb17ee077aa55cd8422b0c80e0f55f5 Mon Sep 17 00:00:00 2001 From: apple-bears Date: Sun, 1 Mar 2026 13:07:30 -0600 Subject: [PATCH] Create a dummy model that prevents nested form fields from inheriting values from parent form's model. --- modules/backend/formwidgets/NestedForm.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/backend/formwidgets/NestedForm.php b/modules/backend/formwidgets/NestedForm.php index c4479f5fc4..ddfea45ca9 100644 --- a/modules/backend/formwidgets/NestedForm.php +++ b/modules/backend/formwidgets/NestedForm.php @@ -2,6 +2,7 @@ use Backend\Classes\FormWidgetBase; use Backend\Widgets\Form; +use Winter\Storm\Database\Model; /** * Nested Form @@ -46,9 +47,23 @@ public function init() $this->previewMode = true; } + $nestedData = $this->getLoadValue(); + + $dummyModel = new class extends Model { + public function __get($key) { + return null; + } + public function __isset($key) { + return false; + } + public function exists() { + return false; + } + }; + $config = $this->makeConfig($this->form); - $config->model = $this->model; - $config->data = $this->getLoadValue(); + $config->model = $dummyModel; + $config->data = $nestedData ?: []; $config->alias = $this->alias . $this->defaultAlias; $config->arrayName = $this->getFieldName(); $config->isNested = true;