]> _ Git - cubist_cms-back.git/commitdiff
wip #6248 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 6 Sep 2023 13:21:59 +0000 (15:21 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 6 Sep 2023 13:21:59 +0000 (15:21 +0200)
src/resources/views/fields/select2_from_array.blade.php

index 16b1166d2064eafeacac1b9e07d1e9688c3390ef..80afbdd6c1005de675bbc0c6ba8a43d3f3e7789e 100644 (file)
@@ -7,12 +7,10 @@
             if(null===$o || $o==='null'){
                 return false;
             }
-            if(!is_array($o)){
+            if(is_scalar($o)){
                 return $o==$key;
-            }else {
-                return in_array($key,$o);
             }
-            return false;
+            return in_array($key,$o);
         }
     }
 
@@ -24,20 +22,21 @@ if($ajax){
 }
 @endphp
 
-    <!-- select2 from array -->
+        <!-- select2 from array -->
 @include('crud::fields.inc.wrapper_start')
 <label>{!! $field['label'] !!}</label>
 @if (isset($field['allows_multiple']) && $field['allows_multiple']==true)
     <input type="hidden" name="{{ $field['name'] }}" value=""/>
 @endif
 <select
-    name="{{ $field['name'] }}@if (isset($field['allows_multiple']) && $field['allows_multiple']==true)[]@endif"
-    style="width: 100%"
-    @include('crud::fields.inc.attributes', ['default_class' =>  'form-control select2_from_array'])
-    @if (isset($field['allows_multiple']) && $field['allows_multiple']==true)multiple @endif
-    @if($ajax) data-ajax="{{$field['ajax']}}" @endif
-    @if($allows_html) data-allow-html="1" @endif
-    data-options="{{ json_encode($field['options']) }}"
+        name="{{ $field['name'] }}@if (isset($field['allows_multiple']) && $field['allows_multiple']==true)[]@endif"
+        style="width: 100%"
+        @include('crud::fields.inc.attributes', ['default_class' =>  'form-control select2_from_array'])
+        @if (isset($field['allows_multiple']) && $field['allows_multiple']==true)multiple @endif
+        @if($ajax) data-ajax="{{$field['ajax']}}" @endif
+        @if($allows_html) data-allow-html="1" @endif
+        data-options="{{ json_encode($field['options']) }}"
+        data-value="{{is_scalar($o)?$o:json_encode($o)}}"
 >
     @if (isset($field['allows_null']) && $field['allows_null']==true)
         @if($is_null)
@@ -60,8 +59,8 @@ if($ajax){
                 }else{
                     $value=$data;
                 }
-
             @endphp
+
             @if(!$is_null && select2_from_array_selected($key,$o))
                 <option value="{{ $key }}" selected {!! $attrs !!}>{{ $value }}</option>
             @elseif(!$ajax || $key==$field['default'])
@@ -92,8 +91,8 @@ if($ajax){
         <link href="{{ asset('packages/select2/dist/css/select2.min.css') }}" rel="stylesheet"
               type="text/css"/>
         <link
-            href="{{ asset('packages/select2-bootstrap-theme/dist/select2-bootstrap.min.css') }}"
-            rel="stylesheet" type="text/css"/>
+                href="{{ asset('packages/select2-bootstrap-theme/dist/select2-bootstrap.min.css') }}"
+                rel="stylesheet" type="text/css"/>
     @endpush
 
     {{-- FIELD JS - will be loaded in the after_scripts section --}}