Browse Source

!2 为Form增加了MAC类型的字段
Merge pull request !2 from 绯末/master

剑走偏锋 4 years ago
parent
commit
a54b1c6850
2 changed files with 34 additions and 0 deletions
  1. 2 0
      src/Form.php
  2. 32 0
      src/Form/Field/Mac.php

+ 2 - 0
src/Form.php

@@ -39,6 +39,7 @@ use Symfony\Component\HttpFoundation\Response;
  * @method Field\Hidden                 hidden($column, $label = '')
  * @method Field\Id                     id($column, $label = '')
  * @method Field\Ip                     ip($column, $label = '')
+ * @method Field\Mac                    mac($column, $label = '')
  * @method Field\Url                    url($column, $label = '')
  * @method Field\Email                  email($column, $label = '')
  * @method Field\Mobile                 mobile($column, $label = '')
@@ -130,6 +131,7 @@ class Form implements Renderable
         'hidden'              => Field\Hidden::class,
         'id'                  => Field\Id::class,
         'ip'                  => Field\Ip::class,
+        'mac'                 => Field\Mac::class,
         'map'                 => Field\Map::class,
         'mobile'              => Field\Mobile::class,
         'month'               => Field\Month::class,

+ 32 - 0
src/Form/Field/Mac.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace Dcat\Admin\Form\Field;
+
+class Mac extends Text
+{
+    public static $js = '@jquery.inputmask';
+    public static $css = '@jquery.inputmask';
+
+    protected $rules = ['nullable', 'mac'];
+
+    /**
+     * @see https://github.com/RobinHerbots/Inputmask#options
+     *
+     * @var array
+     */
+    protected $options = [
+        'alias' => 'mac',
+    ];
+
+    public function render()
+    {
+        $this->inputmask($this->options);
+
+        $this->defaultAttribute('style', 'width: 160px;flex:none');
+
+        $this->prepend('<i class="fa fa-desktop fa-fw"></i>')
+            ->defaultAttribute('style', 'width: 200px');
+
+        return parent::render();
+    }
+}