ソースを参照

支持 info 配置项

xaboy 6 年 前
コミット
198c5f0664
2 ファイル変更23 行追加3 行削除
  1. 4 2
      src/Form.php
  2. 19 1
      src/FormComponentDriver.php

+ 4 - 2
src/Form.php

@@ -176,7 +176,7 @@ class Form
      * Form constructor.
      *
      * @param string $action 提交地址
-     * @param array  $components 组件
+     * @param array $components 组件
      */
     public function __construct($action = '', array $components = [])
     {
@@ -445,6 +445,8 @@ class Form
 
             $fields[] = $field;
             $rule = $component->build();
+            if ($component->info)
+                $rule['info'] = $component->info;
             if (!$component instanceof Hidden)
                 $rule['validate'] = array_merge(isset($rule['validate']) ? $rule['validate'] : [], $component->validate()->build());
             $rules[] = $rule;
@@ -564,7 +566,7 @@ class Form
      * 生成表单快捷方法
      *
      * @param string $action
-     * @param array  $components
+     * @param array $components
      * @return Form
      */
     public static function create($action, array $components = [])

+ 19 - 1
src/FormComponentDriver.php

@@ -49,6 +49,13 @@ abstract class FormComponentDriver implements FormComponentInterFace
     protected $props = [];
 
     /**
+     * info
+     *
+     * @var String
+     */
+    public $info;
+
+    /**
      * 字段的值
      *
      * @var
@@ -145,7 +152,6 @@ abstract class FormComponentDriver implements FormComponentInterFace
      * 设置组件的值
      *
      * @param        $value
-     * @param string $default
      * @return $this
      */
     public function value($value)
@@ -156,6 +162,18 @@ abstract class FormComponentDriver implements FormComponentInterFace
     }
 
     /**
+     * 设置组件的info
+     *
+     * @param string $info
+     * @return $this
+     */
+    public function info($info)
+    {
+        $this->info = (string)$info;
+        return $this;
+    }
+
+    /**
      * 获取组件的值
      *
      * @return string