jqh %!s(int64=5) %!d(string=hai) anos
pai
achega
2a811e1328
Modificáronse 4 ficheiros con 38 adicións e 10 borrados
  1. 2 2
      resources/lang/zh-CN/admin.php
  2. 31 3
      src/Form.php
  3. 2 2
      src/Form/Builder.php
  4. 3 3
      src/Form/Field/Text.php

+ 2 - 2
resources/lang/zh-CN/admin.php

@@ -190,8 +190,8 @@ return [
     'selected_must_less_then'  => '最多只能选择:num个选项',
     'validation' => [
         'match'     => '与 :attribute 不匹配。',
-        'minlength' => ':attribute 字符长度不能于 :min。',
-        'maxlength' => ':attribute 字符长度不能大于 :max。',
+        'minlength' => ':attribute 字符长度不能于 :min。',
+        'maxlength' => ':attribute 字符长度不能超出 :max。',
     ],
     'menu_titles' => [],
 ];

+ 31 - 3
src/Form.php

@@ -275,13 +275,13 @@ class Form implements Renderable
      * @param Repository $model
      * @param \Closure $callback
      */
-    public function __construct(Repository $repository, ?Closure $callback = null, Request $request = null)
+    public function __construct(?Repository $repository = null, ?Closure $callback = null, Request $request = null)
     {
-        $this->repository = Admin::repository($repository);
+        $this->repository = $repository ? Admin::repository($repository) : null;
         $this->callback = $callback;
         $this->request = $request ?: request();
         $this->builder = new Builder($this);
-        $this->isSoftDeletes = $this->repository->isSoftDeletes();
+        $this->isSoftDeletes = $repository ? $this->repository->isSoftDeletes() : false;
 
         $this->setModel(new Fluent());
 
@@ -1085,9 +1085,37 @@ class Form implements Renderable
      */
     public function getKeyName()
     {
+        if (! $this->repository) {
+            return 'id';
+        }
+
         return $this->repository->getKeyName();
     }
 
+    /**
+     * @return string|void
+     */
+    public function getCreatedAtColumn()
+    {
+        if (! $this->repository) {
+            return;
+        }
+
+        return $this->repository->getCreatedAtColumn();
+    }
+
+    /**
+     * @return string|void
+     */
+    public function getUpdatedAtColumn()
+    {
+        if (! $this->repository) {
+            return;
+        }
+
+        return $this->repository->getUpdatedAtColumn();
+    }
+
     /**
      * @return Repository
      */

+ 2 - 2
src/Form/Builder.php

@@ -710,8 +710,8 @@ class Builder
 
         $reservedColumns = [
             $this->form->getKeyName(),
-            $this->form->getRepository()->getCreatedAtColumn(),
-            $this->form->getRepository()->getUpdatedAtColumn(),
+            $this->form->getCreatedAtColumn(),
+            $this->form->getUpdatedAtColumn(),
         ];
 
         $this->fields = $this->fields()->reject(function (Field $field) use (&$reservedColumns) {

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

@@ -67,7 +67,7 @@ class Text extends Field
 
         $attributes = [
             'data-match'       => '#'.$field->getElementId(),
-            'data-match-error' => str_replace([':attribute', ':other'], [$this->column, $name], $error ?: trans('admin.validation.match'))
+            'data-match-error' => str_replace([':attribute', ':other'], [$this->label, $name], $error ?: trans('admin.validation.match'))
         ];
 
         return $this->attribute($attributes);
@@ -86,7 +86,7 @@ class Text extends Field
             'data-minlength'       => $length,
             'data-minlength-error' => str_replace(
                 [':attribute', ':min'],
-                [$this->column, $length],
+                [$this->label, $length],
                 $error ?: trans('admin.validation.minlength')
             ),
         ]);
@@ -113,7 +113,7 @@ JS
             'data-maxlength'       => $length,
             'data-maxlength-error' => str_replace(
                 [':attribute', ':max'],
-                [$this->column, $length],
+                [$this->label, $length],
                 $error ?: trans('admin.validation.maxlength')
             ),
         ]);