Kaynağa Gözat

Merge pull request #1530 from edwinhuish/individual_form_row_field_width

可独立设置 Form Row 的宽度
Jiang Qinghua 3 yıl önce
ebeveyn
işleme
d8596a48d3
1 değiştirilmiş dosya ile 24 ekleme ve 2 silme
  1. 24 2
      src/Form/Row.php

+ 24 - 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 = 12;
+
     /**
      * @var bool
      */
@@ -160,6 +167,19 @@ class Row implements Renderable
         return $this->form->model();
     }
 
+    /**
+     * Set default width for field.
+     *
+     * @param  int  $width
+     * @return $this
+     */
+    public function defaultWidth(int $width = 12)
+    {
+        $this->defaultFieldWidth = $width;
+
+        return $this;
+    }
+
     /**
      * Set width for a incomming field.
      *
@@ -168,7 +188,7 @@ class Row implements Renderable
      */
     public function width($width = 12)
     {
-        $this->defaultFieldWidth = $width;
+        $this->fieldWidth = $width;
 
         return $this;
     }
@@ -197,10 +217,12 @@ class Row implements Renderable
         $field->horizontal($this->horizontal);
 
         $this->fields->push([
-            'width'   => $this->defaultFieldWidth,
+            'width'   => $this->fieldWidth,
             'element' => $field,
         ]);
 
+        $this->fieldWidth = $this->defaultFieldWidth; // reset field width for next field
+
         return $field;
     }
 }