Browse Source

修复在表单用 tab,tab 里面在用 row 引起的问题

youxingxiang 4 years ago
parent
commit
3577a5acd9
3 changed files with 43 additions and 3 deletions
  1. 21 3
      src/Form/Builder.php
  2. 11 0
      src/Form/Concerns/HasRows.php
  3. 11 0
      src/Form/Row.php

+ 21 - 3
src/Form/Builder.php

@@ -797,7 +797,7 @@ class Builder
      */
     protected function removeReservedFields()
     {
-        if (! $this->isMode(static::MODE_CREATE)) {
+        if (!$this->isMode(static::MODE_CREATE)) {
             return;
         }
 
@@ -812,12 +812,30 @@ class Builder
                 && $field instanceof Form\Field\Display;
         };
 
+        $rowFilter = function (array $field) use (&$reservedColumns) {
+            $field = $field['element'];
+            return !(in_array($field->column(), $reservedColumns, true)
+                && $field instanceof Form\Field\Display);
+        };
+
         $this->fields = $this->fields()->reject($reject);
 
+        if ($this->hasRows()) {
+            $rows = array_map(function (Row $row) use ($rowFilter) {
+                $fields = collect($row->fields())->filter($rowFilter)->toArray();
+                return $row->setFields($fields);
+
+            }, $this->rows());
+
+            $this->form->setRows($rows);
+        }
+
         if ($this->form->hasTab()) {
             $this->form->getTab()->getTabs()->transform(function ($item) use ($reject) {
-                if (! empty($item['fields'])) {
-                    $item['fields'] = $item['fields']->reject($reject);
+                if (!empty($item['fields'])) {
+                    $item['fields'] = $item['fields']->filter(function ($field) use ($reject) {
+                        return $field instanceof Row || ($field instanceof Field && !$reject($field));
+                    });
                 }
 
                 return $item;

+ 11 - 0
src/Form/Concerns/HasRows.php

@@ -35,4 +35,15 @@ trait HasRows
     {
         return $this->rows;
     }
+
+    /**
+     * @param array $rows
+     * @return $this
+     */
+    public function setRows(array $rows)
+    {
+        $this->rows = $rows;
+
+        return $this;
+    }
 }

+ 11 - 0
src/Form/Row.php

@@ -116,6 +116,17 @@ class Row implements Renderable
         return $this->fields;
     }
 
+    /**
+     * @param array $fields
+     * @return $this
+     */
+    public function setFields(array $fields)
+    {
+        $this->fields = $fields;
+
+        return $this;
+    }
+
     /**
      * Set width for a incomming field.
      *