Prechádzať zdrojové kódy

自定义KeyValue表单的表头名称

jqh 4 rokov pred
rodič
commit
550726f47f

+ 2 - 2
resources/views/form/keyvalue.blade.php

@@ -15,8 +15,8 @@
         <table class="table table-hover">
             <thead>
             <tr>
-                <th>{{ __('Key') }}</th>
-                <th>{{ __('Value') }}</th>
+                <th>{!! $keyLabel !!}</th>
+                <th>{!! $valueLabel !!}</th>
                 <th style="width: 85px;"></th>
             </tr>
             </thead>

+ 32 - 3
src/Form/Field/KeyValue.php

@@ -10,6 +10,33 @@ class KeyValue extends Field
 {
     const DEFAULT_FLAG_NAME = '_def_';
 
+    protected $keyLabel;
+    protected $valueLabel;
+
+    public function setKeyLabel(?string $label)
+    {
+        $this->keyLabel = $label;
+
+        return $this;
+    }
+
+    public function setValueLabel(?string $label)
+    {
+        $this->keyLabel = $label;
+
+        return $this;
+    }
+
+    public function getKeyLabel()
+    {
+        return $this->keyLabel ?: __('Key');
+    }
+
+    public function getValueLabel()
+    {
+        return $this->valueLabel ?: __('Value');
+    }
+
     /**
      * {@inheritdoc}
      */
@@ -45,8 +72,8 @@ class KeyValue extends Field
 
         $rules["{$this->column}.keys.*"] = 'distinct';
         $rules["{$this->column}.values.*"] = $fieldRules;
-        $attributes["{$this->column}.keys.*"] = __('Key');
-        $attributes["{$this->column}.values.*"] = __('Value');
+        $attributes["{$this->column}.keys.*"] = $this->getKeyLabel();
+        $attributes["{$this->column}.values.*"] = $this->getValueLabel();
 
         $input = $this->prepareValidatorInput($input);
 
@@ -76,7 +103,9 @@ class KeyValue extends Field
         $value = $this->value();
 
         $this->addVariables([
-            'count' => $value ? count($value) : 0,
+            'count'      => $value ? count($value) : 0,
+            'keyLabel'   => $this->getKeyLabel(),
+            'valueLabel' => $this->getValueLabel(),
         ]);
 
         return parent::render();

+ 0 - 1
src/Form/Field/MultipleSelect.php

@@ -3,7 +3,6 @@
 namespace Dcat\Admin\Form\Field;
 
 use Dcat\Admin\Support\Helper;
-use Illuminate\Support\Arr;
 
 class MultipleSelect extends Select
 {