Sfoglia il codice sorgente

wip - add Form::range

jqh 4 anni fa
parent
commit
6ee70c8fd4

+ 32 - 0
resources/views/form/range.blade.php

@@ -0,0 +1,32 @@
+<div class="{{$viewClass['form-group']}} {!! ($errors->has($errorKey['start'].'start') || $errors->has($errorKey['end'].'end')) ? 'has-error' : ''  !!}">
+
+    <label for="{{$id['start']}}" class="{{$viewClass['label']}} control-label">{!! $label !!}</label>
+
+    <div class="{{$viewClass['field']}}">
+
+        @include('admin::form.error')
+
+        <div class="row" style="max-width: 603px">
+            <div class="col-lg-6">
+                <div class="input-group">
+                     <span class="input-group-prepend">
+                        <span class="input-group-text bg-white"><i class="feather icon-edit-2"></i></span>
+                    </span>
+                    <input autocomplete="off" type="text" name="{{$name['start']}}" value="{{ old($column['start'], $value['start'] ?? null) }}" class="form-control {{$class['start']}}" style="width: 150px" {!! $attributes !!} />
+                </div>
+            </div>
+
+            <div class="col-lg-6">
+                <div class="input-group">
+                     <span class="input-group-prepend">
+                        <span class="input-group-text bg-white"><i class="feather icon-edit-2"></i></span>
+                    </span>
+                    <input autocomplete="off" type="text" name="{{$name['end']}}" value="{{ old($column['end'], $value['end'] ?? null) }}" class="form-control {{$class['end']}}" style="width: 150px" {!! $attributes !!} />
+                </div>
+            </div>
+        </div>
+
+        @include('admin::form.help-block')
+
+    </div>
+</div>

+ 2 - 0
src/Form.php

@@ -82,6 +82,7 @@ use Symfony\Component\HttpFoundation\Response;
  * @method Field\KeyValue               keyValue($column, $label = '')
  * @method Field\Tel                    tel($column, $label = '')
  * @method Field\Markdown               markdown($column, $label = '')
+ * @method Field\Range                  range($start, $end, $label = '')
  */
 class Form implements Renderable
 {
@@ -156,6 +157,7 @@ class Form implements Renderable
         'keyValue'       => Field\KeyValue::class,
         'tel'            => Field\Tel::class,
         'markdown'       => Field\Markdown::class,
+        'range'          => Field\Range::class,
     ];
 
     /**

+ 1 - 0
src/Form/EmbeddedForm.php

@@ -58,6 +58,7 @@ use Illuminate\Support\Collection;
  * @method Field\KeyValue               keyValue($column, $label = '')
  * @method Field\Tel                    tel($column, $label = '')
  * @method Field\Markdown               markdown($column, $label = '')
+ * @method Field\Range                  range($start, $end, $label = '')
  */
 class EmbeddedForm
 {

+ 58 - 0
src/Form/Field/Range.php

@@ -0,0 +1,58 @@
+<?php
+
+namespace Dcat\Admin\Form\Field;
+
+use Dcat\Admin\Form\Field;
+
+class Range extends Field
+{
+    /**
+     * Column name.
+     *
+     * @var array
+     */
+    protected $column = [];
+
+    public function __construct($column, $arguments)
+    {
+        $this->column['start'] = $column;
+        $this->column['end'] = $arguments[0];
+
+        array_shift($arguments);
+        $this->label = $this->formatLabel($arguments);
+        $this->id = $this->formatId($this->column);
+    }
+
+    protected function prepareInputValue($value)
+    {
+        if ($value === '') {
+            $value = null;
+        }
+
+        return $value;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function getValidationMessages()
+    {
+        // Default validation message.
+        $messages = parent::getValidationMessages();
+
+        $result = [];
+        foreach ($messages as $key => $message) {
+            $column = explode('.', $key);
+            $rule = array_pop($column);
+            $column = implode('.', $column);
+
+            if ($this->column['start'] === $column) {
+                $result[$column.'start.'.$rule] = $message;
+            } else {
+                $result[$key] = $message;
+            }
+        }
+
+        return $result;
+    }
+}

+ 1 - 0
src/Form/NestedForm.php

@@ -61,6 +61,7 @@ use Illuminate\Support\Collection;
  * @method Field\KeyValue               keyValue($column, $label = '')
  * @method Field\Tel                    tel($column, $label = '')
  * @method Field\Markdown               markdown($column, $label = '')
+ * @method Field\Range                  range($start, $end, $label = '')
  */
 class NestedForm
 {

+ 1 - 0
src/Form/Row.php

@@ -58,6 +58,7 @@ use Illuminate\Contracts\Support\Renderable;
  * @method Field\KeyValue               keyValue($column, $label = '')
  * @method Field\Tel                    tel($column, $label = '')
  * @method Field\Markdown               markdown($column, $label = '')
+ * @method Field\Range                  range($start, $end, $label = '')
  */
 class Row implements Renderable
 {

+ 1 - 0
src/Widgets/Form.php

@@ -73,6 +73,7 @@ use Illuminate\Validation\Validator;
  * @method Field\KeyValue       keyValue($column, $label = '')
  * @method Field\Tel            tel($column, $label = '')
  * @method Field\Markdown       markdown($column, $label = '')
+ * @method Field\Range          range($start, $end, $label = '')
  */
 class Form implements Renderable
 {