فهرست منبع

Merge pull request #1770 from pianzhou2021/2.0

fix-issue-1742 修复embeds中无法上传图片的问题
Tall Libra 3 سال پیش
والد
کامیت
2b5590451f
3فایلهای تغییر یافته به همراه42 افزوده شده و 1 حذف شده
  1. 15 1
      src/Form/Concerns/HasFiles.php
  2. 13 0
      src/Form/Field/Embeds.php
  3. 14 0
      src/Form/Field/File.php

+ 15 - 1
src/Form/Concerns/HasFiles.php

@@ -5,6 +5,7 @@ namespace Dcat\Admin\Form\Concerns;
 use Dcat\Admin\Contracts\UploadField as UploadFieldInterface;
 use Dcat\Admin\Form\Builder;
 use Dcat\Admin\Form\Field;
+use Dcat\Admin\Form\Field\Embeds;
 use Dcat\Admin\Form\NestedForm;
 use Dcat\Admin\Support\WebUploader;
 use Illuminate\Support\Arr;
@@ -65,7 +66,20 @@ trait HasFiles
      */
     public function findFieldByName(?string $column)
     {
-        return $this->builder->field($column);
+        if ($field = $this->builder->field($column)) {
+            return $field;
+        }
+
+        $columns = explode('.', $column);
+        $field = $this->builder->field($columns[0]);
+        unset($columns[0]);
+        foreach ($columns as $column) {
+            if ($field instanceof Embeds) {
+                $field = $field->findFieldByName($column);
+            }
+        }
+
+        return $field;
     }
 
     /**

+ 13 - 0
src/Form/Field/Embeds.php

@@ -268,4 +268,17 @@ class Embeds extends Field
 
         return parent::render();
     }
+
+    /**
+     * 根据字段名称查找字段.
+     *
+     * @param  string  $column
+     * @return Field|null
+     */
+    public function findFieldByName($name)
+    {
+        return $this->buildEmbeddedForm()->fields()->first(function (Field $field) use ($name) {
+            return $field->column() == $name;
+        });
+    }
 }

+ 14 - 0
src/Form/Field/File.php

@@ -237,4 +237,18 @@ class File extends Field implements UploadFieldInterface
 
         return $this;
     }
+
+    /**
+     * Set key for error message.
+     *
+     * @param  string|array  $key
+     * @return $this
+     */
+    public function setErrorKey($key)
+    {
+        parent::setErrorKey($key);
+        $this->options['formData']['upload_column'] = $key;
+
+        return $this;
+    }
 }