jqh 4 年之前
父节点
当前提交
0f765ce345

+ 1 - 0
src/Form/BlockForm.php

@@ -106,6 +106,7 @@ class BlockForm extends WidgetForm
         $field->attribute(Field::BUILD_IGNORE, true);
 
         $field->setForm($this->form);
+        $field->setParent($this);
         $field->width($this->width['field'], $this->width['label']);
 
         $field::requireAssets();

+ 1 - 1
src/Form/Concerns/HandleCascadeFields.php

@@ -18,7 +18,7 @@ trait HandleCascadeFields
 
         call_user_func($closure, $this);
 
-        $group->end();
+        $this->html($group->end())->plain();
 
         return $group;
     }

+ 18 - 1
src/Form/Field.php

@@ -138,7 +138,12 @@ class Field implements Renderable
      *
      * @var Form|WidgetForm
      */
-    protected $form = null;
+    protected $form;
+
+    /**
+     * @var WidgetForm
+     */
+    protected $parent;
 
     /**
      * View for field to render.
@@ -401,6 +406,18 @@ class Field implements Renderable
         return $this;
     }
 
+    /**
+     * @param WidgetForm $form
+     *
+     * @return $this
+     */
+    public function setParent($form = null)
+    {
+        $this->parent = $form;
+
+        return $this;
+    }
+
     /**
      * @return Fluent
      */

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

@@ -79,7 +79,7 @@ trait CanCascadeFields
     {
         $this->conditions[] = compact('operator', 'value', 'closure');
 
-        $this->form->cascadeGroup($closure, [
+        ($this->parent ?: $this->form)->cascadeGroup($closure, [
             'column' => $this->column(),
             'index'  => count($this->conditions) - 1,
             'class'  => $this->getCascadeClass($value, $operator),

+ 2 - 2
src/Form/Field/CascadeGroup.php

@@ -63,10 +63,10 @@ HTML;
     }
 
     /**
-     * @return void
+     * @return string
      */
     public function end()
     {
-        $this->form->html('</div>')->plain();
+        return '</div>';
     }
 }

+ 1 - 0
src/Form/NestedForm.php

@@ -276,6 +276,7 @@ class NestedForm extends WidgetForm
         $this->fields->push($field);
 
         $field->setForm($this->form);
+        $field->setParent($this);
 
         if ($this->layout()->hasColumns()) {
             $this->layout()->addField($field);