Browse Source

可独立设置 Row 的宽度

Edwin Xu 3 years ago
parent
commit
3bd44566e1
1 changed files with 11 additions and 2 deletions
  1. 11 2
      src/Form/Row.php

+ 11 - 2
src/Form/Row.php

@@ -91,6 +91,13 @@ class Row implements Renderable
      */
     protected $defaultFieldWidth = 12;
 
+    /**
+     * field width for appended field.
+     *
+     * @var int
+     */
+    protected $fieldWidth;
+
     /**
      * @var bool
      */
@@ -168,7 +175,7 @@ class Row implements Renderable
      */
     public function width($width = 12)
     {
-        $this->defaultFieldWidth = $width;
+        $this->fieldWidth = $width;
 
         return $this;
     }
@@ -197,10 +204,12 @@ class Row implements Renderable
         $field->horizontal($this->horizontal);
 
         $this->fields->push([
-            'width'   => $this->defaultFieldWidth,
+            'width'   => $this->fieldWidth ?: $this->defaultFieldWidth,
             'element' => $field,
         ]);
 
+        unset($this->fieldWidth); // unset field width for next field
+
         return $field;
     }
 }