]> _ Git - cubist_cms-back.git/commitdiff
wip #5401 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 30 Jun 2023 16:31:42 +0000 (18:31 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 30 Jun 2023 16:31:42 +0000 (18:31 +0200)
src/app/Magic/Fields/CheckboxMultiple.php [new file with mode: 0644]
src/resources/views/fields/checkbox_multiple.blade.php [new file with mode: 0644]

diff --git a/src/app/Magic/Fields/CheckboxMultiple.php b/src/app/Magic/Fields/CheckboxMultiple.php
new file mode 100644 (file)
index 0000000..f3bf8c0
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+
+namespace Cubist\Backpack\Magic\Fields;
+
+class CheckboxMultiple extends SelectFromArrayMultiple
+{
+    protected $_adminType = 'checkbox_multiple';
+}
diff --git a/src/resources/views/fields/checkbox_multiple.blade.php b/src/resources/views/fields/checkbox_multiple.blade.php
new file mode 100644 (file)
index 0000000..8298c96
--- /dev/null
@@ -0,0 +1,80 @@
+@php
+    $o=$field['value'] ?? old(square_brackets_to_dots($field['name']))??$field['default'];
+
+    $is_null=null===$o || $o==='null';
+    if(!function_exists('select2_from_array_selected')){
+        function select2_from_array_selected($key,$o){
+            if(null===$o || $o==='null'){
+                return false;
+            }
+            if(!is_array($o)){
+                return $o==$key;
+            }else {
+                return in_array($key,$o);
+            }
+            return false;
+        }
+    }
+@endphp
+
+    <!-- select2 from array -->
+@include('crud::fields.inc.wrapper_start')
+<label>{!! $field['label'] !!}</label>
+<ul class="checkbox-multiple">
+    @if (count($field['options']))
+        @foreach ($field['options'] as $key => $data)
+            @php
+                if(is_array($data)){
+                    $value=$data['value'];
+                    unset($data['value']);
+                }else{
+                    $value=$data;
+                }
+            @endphp
+            <li><label><input type="checkbox" name="{{$field['name']}}[]" value="{{$key}}"
+                              @if(!$is_null && select2_from_array_selected($key,$o)) checked @endif> {{$value}}</label>
+            </li>
+        @endforeach
+    @endif
+</ul>
+
+@if(isset($field['show_selected_option']) && $field['show_selected_option'])
+    <p class="help-block">{{__('Valeur actuelle : ')}} <span class="selectFromArrayCurrentValue"></span></p>
+@endif
+{{-- HINT --}}
+@if (isset($field['hint']))
+    <p class="help-block">{!! $field['hint'] !!}</p>
+@endif
+
+
+@include('crud::fields.inc.wrapper_end')
+
+{{-- ########################################## --}}
+{{-- Extra CSS and JS for this particular field --}}
+{{-- If a field type is shown multiple times on a form, the CSS and JS will only be loaded once --}}
+@if ($crud->checkIfFieldIsFirstOfItsType($field))
+    {{-- FIELD CSS - will be loaded in the after_styles section --}}
+    @push('crud_fields_styles')
+        <style>
+            ul.checkbox-multiple {
+                list-style-type: none;
+                padding-left: 0;
+            }
+            ul.checkbox-multiple input{
+                margin-right: 10px;
+            }
+            ul.checkbox-multiple label{
+                font-weight: 400;
+            }
+        </style>
+    @endpush
+    {{-- FIELD JS - will be loaded in the after_scripts section --}}
+    @push('crud_fields_scripts')
+        <script>
+
+        </script>
+    @endpush
+
+@endif
+{{-- End of Extra CSS and JS --}}
+{{-- ########################################## --}}