Skip to content

Commit 25b7a4b

Browse files
author
Eugene Tupikov
committed
#249 try to use copy of a model to set default value before passing it to a widget
1 parent 311e5d2 commit 25b7a4b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/components/BaseColumn.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ abstract class BaseColumn extends BaseObject
147147
* @since 2.18.0
148148
*/
149149
public $columnOptions = [];
150-
150+
151151
/**
152152
* @var Model|ActiveRecordInterface|array
153153
*/
@@ -584,9 +584,13 @@ protected function renderWidget($type, $name, $value, $options)
584584

585585
$model = $this->getModel();
586586
if ($model instanceof Model) {
587-
$model->{$this->name} = $value;
587+
// @see https://github.com/unclead/yii2-multiple-input/issues/249
588+
// don't modify original model
589+
$cloneModel = clone $model;
590+
$cloneModel->{$this->name} = $value;
591+
588592
$widgetOptions = [
589-
'model' => $model,
593+
'model' => $cloneModel,
590594
'attribute' => $this->name,
591595
'value' => $value,
592596
'options' => [

0 commit comments

Comments
 (0)