瀏覽代碼

调整数据表单字段默认值获取写法

jqh 5 年之前
父節點
當前提交
76dfd48c95
共有 1 個文件被更改,包括 13 次插入3 次删除
  1. 13 3
      src/Form/Field.php

+ 13 - 3
src/Form/Field.php

@@ -528,10 +528,9 @@ class Field implements Renderable
     {
         if (is_null($value)) {
             if (
-                (is_null($this->value) || (is_array($this->value) && empty($this->value)))
-                && (method_exists($this->form, 'isCreating') && $this->form->isCreating())
+                $this->value === null
+                || (is_array($this->value) && empty($this->value))
             ) {
-                // 只有creating页面才允许使用default
                 return $this->default();
             }
 
@@ -575,6 +574,14 @@ class Field implements Renderable
     public function default($default = null)
     {
         if ($default === null) {
+            if (
+                $this->form
+                && method_exists($this->form, 'isCreating')
+                && ! $this->form->isCreating()
+            ) {
+                return null;
+            }
+
             if ($this->default instanceof \Closure) {
                 return call_user_func($this->default, $this->form);
             }
@@ -634,6 +641,9 @@ class Field implements Renderable
         return $this;
     }
 
+    /**
+     * @return mixed
+     */
     public function old()
     {
         return old($this->column, $this->value());