فهرست منبع

Form::hasMany和Form::array支持column以及row布局

jqh 4 سال پیش
والد
کامیت
9e6107b5cc
2فایلهای تغییر یافته به همراه18 افزوده شده و 27 حذف شده
  1. 3 3
      src/Form/Field/CanCascadeFields.php
  2. 15 24
      src/Form/NestedForm.php

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

@@ -132,7 +132,7 @@ trait CanCascadeFields
         })->toJson();
 
         $script = <<<JS
-(function () {
+Dcat.init('{$this->getElementClassSelector()}', function (\$this) {
     var compare = function (a, b, o) {
         if (! $.isArray(b)) {
             return operator_table[o](a, b)
@@ -182,7 +182,7 @@ trait CanCascadeFields
     };
     var cascade_groups = {$cascadeGroups}, event = '{$this->cascadeEvent}';
 
-    $('{$this->getElementClassSelector()}').on(event, function (e) {
+    \$this.on(event, function (e) {
         {$this->getFormFrontValue()}
 
         cascade_groups.forEach(function (event) {
@@ -194,7 +194,7 @@ trait CanCascadeFields
             }
         });
     }).trigger(event);
-})();
+});
 JS;
 
         Admin::script($script);

+ 15 - 24
src/Form/NestedForm.php

@@ -10,11 +10,6 @@ use Illuminate\Support\Collection;
 
 class NestedForm extends WidgetForm
 {
-    use Form\Concerns\HandleCascadeFields;
-    use Form\Concerns\HasRows;
-    use Form\Concerns\HasTabs;
-    use Form\Concerns\HasLayout;
-
     const DEFAULT_KEY_NAME = '__LA_KEY__';
 
     const REMOVE_FLAG_NAME = '_remove_';
@@ -274,14 +269,14 @@ class NestedForm extends WidgetForm
     }
 
     /**
-     * @param Field $field
-     *
-     * @return $this
+     * {@inheritDoc}
      */
     public function pushField(Field $field)
     {
         $this->fields->push($field);
 
+        $field->setForm($this->form);
+
         if ($this->layout()->hasColumns()) {
             $this->layout()->addField($field);
         }
@@ -303,6 +298,18 @@ class NestedForm extends WidgetForm
         return $this;
     }
 
+    protected function resolveField($method, $arguments)
+    {
+        if ($className = Form::findFieldClass($method)) {
+            $column = Arr::get($arguments, 0, '');
+
+            /* @var Field $field */
+            $field = new $className($column, array_slice($arguments, 1));
+
+            return $this->formatField($field);
+        }
+    }
+
     /**
      * Get fields of this form.
      *
@@ -372,22 +379,6 @@ class NestedForm extends WidgetForm
         return Helper::formatElementName($name ?: $this->relationName);
     }
 
-    protected function resolveField($method, $arguments)
-    {
-        if ($className = Form::findFieldClass($method)) {
-            $column = Arr::get($arguments, 0, '');
-
-            /* @var Field $field */
-            $field = new $className($column, array_slice($arguments, 1));
-
-            $field->setForm($this->form);
-
-            $field = $this->formatField($field);
-
-            return $field;
-        }
-    }
-
     /**
      * Add nested-form fields dynamically.
      *