فهرست منبع

修复select表单placeholder设置不生效问题

jqh 5 سال پیش
والد
کامیت
f728b81889
1فایلهای تغییر یافته به همراه17 افزوده شده و 3 حذف شده
  1. 17 3
      src/Form/Field/Select.php

+ 17 - 3
src/Form/Field/Select.php

@@ -241,7 +241,7 @@ JS;
             'allowClear'  => true,
             'allowClear'  => true,
             'placeholder' => [
             'placeholder' => [
                 'id'   => '',
                 'id'   => '',
-                'text' => trans('admin.choose'),
+                'text' => $this->placeholder(),
             ],
             ],
         ], $this->config);
         ], $this->config);
 
 
@@ -288,7 +288,7 @@ JS;
     {
     {
         $configs = array_merge([
         $configs = array_merge([
             'allowClear'         => true,
             'allowClear'         => true,
-            'placeholder'        => $this->label,
+            'placeholder'        => $this->placeholder(),
             'minimumInputLength' => 1,
             'minimumInputLength' => 1,
         ], $this->config);
         ], $this->config);
 
 
@@ -375,7 +375,7 @@ JS;
             'allowClear'  => true,
             'allowClear'  => true,
             'placeholder' => [
             'placeholder' => [
                 'id'   => '',
                 'id'   => '',
-                'text' => $this->label,
+                'text' => $this->placeholder(),
             ],
             ],
         ], $this->config);
         ], $this->config);
 
 
@@ -403,6 +403,20 @@ JS;
         return parent::render();
         return parent::render();
     }
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
+    public function placeholder($placeholder = null)
+    {
+        if ($placeholder === null) {
+            return $this->placeholder ?: $this->label;
+        }
+
+        $this->placeholder = $placeholder;
+
+        return $this;
+    }
+
     /**
     /**
      * @return void
      * @return void
      */
      */