浏览代码

radio /checkbox inline

jqh 5 年之前
父节点
当前提交
59887a7591

+ 1 - 3
resources/views/form/checkbox.blade.php

@@ -6,9 +6,7 @@
 
         @include('admin::form.error')
 
-        <div class="d-flex">
-            {!! $checkbox !!}
-        </div>
+        {!! $checkbox !!}
 
         <input type="hidden" name="{{$name}}[]">
 

+ 1 - 3
resources/views/form/radio.blade.php

@@ -6,9 +6,7 @@
 
         @include('admin::form.error')
 
-        <div class="d-flex">
-            {!! $radio !!}
-        </div>
+        {!! $radio !!}
 
         @include('admin::form.help-block')
 

+ 5 - 4
resources/views/helpers/scaffold.blade.php

@@ -1,14 +1,11 @@
 @php
     $timestamps = new \Dcat\Admin\Widgets\Checkbox('timestamps');
-    $timestamps->inline();
     $timestamps->options([1 => 'Created_at & Updated_at'])->check(1);
 
     $soft = new \Dcat\Admin\Widgets\Checkbox('soft_deletes');
-    $soft->inline();
     $soft->options([1 => ucfirst(trans('admin.scaffold.soft_delete'))]);
 
     $actionCreators = new \Dcat\Admin\Widgets\Checkbox('create[]');
-    $actionCreators->inline();
     $actionCreators->options([
         'migration' => ucfirst(trans('admin.scaffold.create_migration')),
         'model' => ucfirst(trans('admin.scaffold.create_model')),
@@ -94,7 +91,9 @@
 
                 <div class="form-group">
                     <div class="col-sm-offset-1 col-sm-11">
-                        {!! $actionCreators->render(); !!}
+                        <div class="d-flex">
+                            {!! $actionCreators->render(); !!}
+                        </div>
                     </div>
                 </div>
 
@@ -196,8 +195,10 @@
                 </div>
 
                 <div class='form-group pull-right' style="margin-right: 20px; margin-top: 5px;">
+                    <div class="d-flex">
                     {!! $timestamps->render() !!}
                     {!! $soft->render() !!}
+                    </div>
                 </div>
 
                 <div class="form-group pull-right" style="margin-right: 20px;">

+ 9 - 1
resources/views/widgets/checkbox.blade.php

@@ -1,3 +1,7 @@
+@if($inline)
+<div class="d-flex">
+@endif
+
 @foreach($options as $k => $label)
     <div class="vs-checkbox-con vs-checkbox-{{ $style }}" style="margin-right: {{ $right }}">
         <input {!! in_array($k, $disabled) ? 'disabled' : '' !!} value="{{$k}}" {!! $attributes !!} {!! (in_array($k, $checked)) ? 'checked' : '' !!}>
@@ -10,4 +14,8 @@
         <span>{!! $label !!}</span>
         @endif
     </div>
-@endforeach
+@endforeach
+
+@if($inline)
+</div>
+@endif

+ 9 - 1
resources/views/widgets/radio.blade.php

@@ -1,3 +1,7 @@
+@if($inline)
+<div class="d-flex">
+@endif
+
 @foreach($options as $k => $label)
     <div class="vs-radio-con vs-radio-success{{ $style }}" style="margin-right: {{ $right }}">
         <input {!! in_array($k, $disabled) ? 'disabled' : '' !!} value="{{$k}}" {!! $attributes !!} {!! ($checked == $k && $checked !== null) ? 'checked' : '' !!}>
@@ -9,4 +13,8 @@
             <span>{!! $label !!}</span>
         @endif
     </div>
-@endforeach
+@endforeach
+
+@if($inline)
+</div>
+@endif

+ 2 - 2
src/Form/Field/Checkbox.php

@@ -81,7 +81,7 @@ class Checkbox extends MultipleSelect
             );
         }
 
-        $checkbox = new WidgetCheckbox(
+        $checkbox = WidgetCheckbox::make(
             $this->getElementName().'[]',
             $this->options,
             $this->style
@@ -91,7 +91,7 @@ class Checkbox extends MultipleSelect
             $checkbox->disable();
         }
 
-        $checkbox->check(old($this->column, $this->value()));
+        $checkbox->inline()->check(old($this->column, $this->value()));
 
         $this->addVariables([
             'checkbox' => $checkbox,

+ 2 - 2
src/Form/Field/Radio.php

@@ -53,13 +53,13 @@ class Radio extends Field
             );
         }
 
-        $radio = new WidgetRadio($this->getElementName(), $this->options, $this->style);
+        $radio = WidgetRadio::make($this->getElementName(), $this->options, $this->style);
 
         if ($this->attributes['disabled'] ?? false) {
             $radio->disable();
         }
 
-        $radio->check(old($this->column, $this->value()));
+        $radio->inline()->check(old($this->column, $this->value()));
 
         $this->addVariables([
             'radio' => $radio,

+ 17 - 0
src/Widgets/Radio.php

@@ -20,6 +20,8 @@ class Radio extends Widget
 
     protected $size;
 
+    protected $inline = false;
+
     public function __construct(
         ?string $name = null,
         array $options = [],
@@ -78,6 +80,20 @@ class Radio extends Widget
         return $this;
     }
 
+    /**
+     * 是否排成一行.
+     *
+     * @param bool $inine
+     *
+     * @return $this
+     */
+    public function inline(bool $inine = true)
+    {
+        $this->inline = $inine;
+
+        return $this;
+    }
+
     /**
      * 设置禁选的选项.
      *
@@ -176,6 +192,7 @@ class Radio extends Widget
             'disabled'   => $this->disabledValues,
             'right'      => $this->right,
             'size'       => $this->size,
+            'inline'     => $this->inline,
         ];
     }