Fix setting default values for repeater in update context (#4098)
Credit to @CptMeatball
This commit is contained in:
parent
331c8f4383
commit
16ca521cd0
|
|
@ -268,6 +268,7 @@ class Repeater extends FormWidgetBase
|
||||||
$config->alias = $this->alias . 'Form'.$index;
|
$config->alias = $this->alias . 'Form'.$index;
|
||||||
$config->arrayName = $this->getFieldName().'['.$index.']';
|
$config->arrayName = $this->getFieldName().'['.$index.']';
|
||||||
$config->isNested = true;
|
$config->isNested = true;
|
||||||
|
$config->enableDefaults = self::$onAddItemCalled;
|
||||||
|
|
||||||
$widget = $this->makeWidget('Backend\Widgets\Form', $config);
|
$widget = $this->makeWidget('Backend\Widgets\Form', $config);
|
||||||
$widget->bindToController();
|
$widget->bindToController();
|
||||||
|
|
|
||||||
|
|
@ -1071,7 +1071,7 @@ class Form extends WidgetBase
|
||||||
$field = $this->allFields[$field];
|
$field = $this->allFields[$field];
|
||||||
}
|
}
|
||||||
|
|
||||||
$defaultValue = !$this->model->exists
|
$defaultValue = $this->shouldFetchDefaultValues()
|
||||||
? $field->getDefaultFromData($this->data)
|
? $field->getDefaultFromData($this->data)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
|
@ -1081,6 +1081,18 @@ class Form extends WidgetBase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if default values should be taken from data.
|
||||||
|
* This should be done when model exists or when explicitly configured
|
||||||
|
*/
|
||||||
|
protected function shouldFetchDefaultValues() {
|
||||||
|
$enableDefaults = object_get($this->config, 'enableDefaults');
|
||||||
|
if ($enableDefaults === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !$this->model->exists || $enableDefaults;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a HTML encoded value containing the other fields this
|
* Returns a HTML encoded value containing the other fields this
|
||||||
* field depends on
|
* field depends on
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue