Bläddra i källkod

修复数据表单编辑页面显示默认值的bug

jqh 5 år sedan
förälder
incheckning
d636a148ed
2 ändrade filer med 10 tillägg och 2 borttagningar
  1. 9 1
      src/Form/Field.php
  2. 1 1
      src/Form/Field/Tags.php

+ 9 - 1
src/Form/Field.php

@@ -527,7 +527,15 @@ class Field implements Renderable
     public function value($value = null)
     {
         if (is_null($value)) {
-            return is_null($this->value) ? $this->default() : $this->value;
+            if (
+                (is_null($this->value) || (is_array($this->value) && empty($this->value)))
+                && (method_exists($this->form, 'isCreating') && $this->form->isCreating())
+            ) {
+                // 只有creating页面才允许使用default
+                return $this->default();
+            }
+
+            return $this->value;
         }
 
         $this->value = $value;

+ 1 - 1
src/Form/Field/Tags.php

@@ -149,7 +149,7 @@ class Tags extends Field
     public function value($value = null)
     {
         if (is_null($value)) {
-            return empty($this->value) ? Helper::array($this->default()) : $this->value;
+            return Helper::array(parent::value());
         }
 
         $this->value = Helper::array($value);