|
@@ -62,6 +62,11 @@ class Field implements Renderable
|
|
|
*/
|
|
|
protected $default;
|
|
|
|
|
|
+ /**
|
|
|
+ * @var bool
|
|
|
+ */
|
|
|
+ protected $allowDefaultValueInEditPage = false;
|
|
|
+
|
|
|
/**
|
|
|
* Element label.
|
|
|
*
|
|
@@ -620,22 +625,26 @@ class Field implements Renderable
|
|
|
/**
|
|
|
* Get or set default value for field.
|
|
|
*
|
|
|
- * @param $default
|
|
|
+ * @param mixed $default
|
|
|
+ * @param bool $edit
|
|
|
*
|
|
|
* @return $this|mixed
|
|
|
*/
|
|
|
- public function default($default = null)
|
|
|
+ public function default($default = null, bool $edit = false)
|
|
|
{
|
|
|
if ($default === null) {
|
|
|
if (
|
|
|
$this->form
|
|
|
&& method_exists($this->form, 'isCreating')
|
|
|
&& ! $this->form->isCreating()
|
|
|
+ && ! $this->allowDefaultValueInEditPage
|
|
|
) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if ($this->default instanceof \Closure) {
|
|
|
+ $this->default->bindTo($this->data());
|
|
|
+
|
|
|
return call_user_func($this->default, $this->form);
|
|
|
}
|
|
|
|
|
@@ -643,6 +652,7 @@ class Field implements Renderable
|
|
|
}
|
|
|
|
|
|
$this->default = $default;
|
|
|
+ $this->allowDefaultValueInEditPage = $edit;
|
|
|
|
|
|
return $this;
|
|
|
}
|