Browse Source

修复Form::tree无法设置readOnly模式bug

jqh 5 years ago
parent
commit
21f597fb7c
1 changed files with 19 additions and 2 deletions
  1. 19 2
      src/Form/Field/Tree.php

+ 19 - 2
src/Form/Field/Tree.php

@@ -60,6 +60,11 @@ class Tree extends Field
      */
     protected $filterParents = true;
 
+    /**
+     * @var bool
+     */
+    protected $readOnly = false;
+
     /**
      * @param array|Arrayable|\Closure $data exp:
      *     {
@@ -91,6 +96,18 @@ class Tree extends Field
         return $this;
     }
 
+    /**
+     * Set the field as readonly mode.
+     *
+     * @return $this
+     */
+    public function readOnly()
+    {
+        $this->readOnly = true;
+
+        return $this;
+    }
+
     /**
      * @param string $idColumn
      * @param string $textColumn
@@ -142,7 +159,7 @@ class Tree extends Field
                 $v['state']['selected'] = true;
             }
 
-            if (!empty($this->attributes['disabled'])) {
+            if ($this->readOnly) {
                 $v['state']['disabled'] = true;
             }
 
@@ -231,7 +248,7 @@ class Tree extends Field
             1 => trans('admin.selectall'),
             2 => trans('admin.expand')
         ]);
-        if (!empty($this->attributes['disabled'])) {
+        if ($this->readOnly) {
             $checkboxes->disabled(1);
         }