浏览代码

工具表单增加resetButton与submitButton方法

jqh 4 年之前
父节点
当前提交
0b40ea8048
共有 3 个文件被更改,包括 41 次插入7 次删除
  1. 12 6
      src/Form/Field.php
  2. 1 1
      src/Form/Field/Tree.php
  3. 28 0
      src/Widgets/Form.php

+ 12 - 6
src/Form/Field.php

@@ -764,31 +764,37 @@ class Field implements Renderable
     /**
      * Set the field automatically get focus.
      *
+     * @param bool $value
+     *
      * @return $this
      */
-    public function autofocus()
+    public function autofocus(bool $value = true)
     {
-        return $this->attribute('autofocus', true);
+        return $this->attribute('autofocus', $value);
     }
 
     /**
      * Set the field as readonly mode.
      *
+     * @param bool $value
+     *
      * @return $this
      */
-    public function readOnly()
+    public function readOnly(bool $value = true)
     {
-        return $this->attribute('readonly', true);
+        return $this->attribute('readonly', $value);
     }
 
     /**
      * Set field as disabled.
      *
+     * @param bool $value
+     *
      * @return $this
      */
-    public function disable()
+    public function disable(bool $value = true)
     {
-        return $this->attribute('disabled', true);
+        return $this->attribute('disabled', $value);
     }
 
     /**

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

@@ -85,7 +85,7 @@ class Tree extends Field
     /**
      * {@inheritDoc}
      */
-    public function readOnly()
+    public function readOnly(bool $value = true)
     {
         $this->readOnly = true;
 

+ 28 - 0
src/Widgets/Form.php

@@ -443,12 +443,38 @@ class Form implements Renderable
         return $this;
     }
 
+    /**
+     * @param bool $value
+     *
+     * @return $this
+     */
+    public function submitButton(bool $value = true)
+    {
+        $this->buttons['submit'] = $value;
+
+        return $this;
+    }
+
+    /**
+     * @param bool $value
+     *
+     * @return $this
+     */
+    public function resetButton(bool $value = true)
+    {
+        $this->buttons['reset'] = $value;
+
+        return $this;
+    }
+
     /**
      * Disable reset button.
      *
      * @param bool $value
      *
      * @return $this
+     *
+     * @deprecated 即将废弃,请使用 resetButton 代替
      */
     public function disableResetButton(bool $value = true)
     {
@@ -463,6 +489,8 @@ class Form implements Renderable
      * @param bool $value
      *
      * @return $this
+     *
+     * @deprecated 即将废弃,请使用 submitButton 代替
      */
     public function disableSubmitButton(bool $value = true)
     {