diff --git a/modules/backend/formwidgets/Repeater.php b/modules/backend/formwidgets/Repeater.php index 70205ff15..42cc754c5 100644 --- a/modules/backend/formwidgets/Repeater.php +++ b/modules/backend/formwidgets/Repeater.php @@ -114,7 +114,9 @@ class Repeater extends FormWidgetBase $itemIndexes = post(self::INDEX_PREFIX.$this->formField->getName(false), $loadValue); - if (!is_array($itemIndexes)) return; + if (!is_array($itemIndexes)) { + return; + } foreach ($itemIndexes as $itemIndex) { $this->makeItemFormWidget($itemIndex); @@ -125,13 +127,16 @@ class Repeater extends FormWidgetBase protected function makeItemFormWidget($index = 0) { $loadValue = $this->getLoadValue(); - if (!is_array($loadValue)) $loadValue = []; + if (!is_array($loadValue)) { + $loadValue = []; + } $config = $this->makeConfig($this->form); $config->model = $this->model; $config->data = array_get($loadValue, $index, []); $config->alias = $this->alias . 'Form'.$index; $config->arrayName = $this->formField->getName().'['.$index.']'; + $config->isNested = true; $widget = $this->makeWidget('Backend\Widgets\Form', $config); $widget->bindToController(); diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index 6f246139e..c9ec6cdd1 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -63,6 +63,12 @@ class Form extends WidgetBase */ public $arrayName; + /** + * @var bool Used to flag that this form is being rendered as part of another form, + * a good indicator to expect that the form model and dataset values will differ. + */ + public $isNested = false; + // // Object properties // @@ -124,8 +130,9 @@ class Form extends WidgetBase 'secondaryTabs', 'model', 'data', - 'arrayName', 'context', + 'arrayName', + 'isNested', ]); $this->widgetManager = WidgetManager::instance(); @@ -1070,7 +1077,7 @@ class Form extends WidgetBase ])); } - $fieldOptions = $this->model->$fieldOptions($field->value, $field->fieldName); + $fieldOptions = $this->model->$fieldOptions($field->value, $field->fieldName, $this->data); } return $fieldOptions;