]> _ Git - cubist_cms-back.git/commitdiff
fix #2870 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 13 Aug 2019 15:45:48 +0000 (17:45 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 13 Aug 2019 15:45:48 +0000 (17:45 +0200)
src/resources/views/fields/select2_from_array.blade.php

index 4e65f418540ddf0a0de511cec921626c0fa26a14..c9a64aac6b03a95a6a28ad6312bfd8c4b3adce2b 100644 (file)
@@ -1,3 +1,7 @@
+@php
+    $is_null=null===old(square_brackets_to_dots($field['name'])) && null===$field['value'];
+@endphp
+
 <!-- select2 from array -->
 <div @include('crud::inc.field_wrapper_attributes') >
     <label>{!! $field['label'] !!}</label>
     >
 
         @if (isset($field['allows_null']) && $field['allows_null']==true)
-            <option value="">-</option>
+            @if($is_null)
+                <option value="" selected>-</option>
+            @else
+                <option value="">-</option>
+            @endif
         @endif
 
         @if (count($field['options']))
             @foreach ($field['options'] as $key => $value)
-                @if((old(square_brackets_to_dots($field['name'])) && (
+                @if(
+                !$is_null && (
+                (old(square_brackets_to_dots($field['name'])) && (
                         $key == old(square_brackets_to_dots($field['name'])) ||
                         (is_array(old(square_brackets_to_dots($field['name']))) &&
                         in_array($key, old(square_brackets_to_dots($field['name'])))))) ||
                         (null === old(square_brackets_to_dots($field['name'])) &&
                             ((isset($field['value']) && (
-                                        $key == $field['value'] || (
+                                        ($key == $field['value'] && null !== $field['value'] )|| (
                                                 is_array($field['value']) &&
                                                 in_array($key, $field['value'])
                                                 )
@@ -32,7 +42,7 @@
                                             )
                                         )
                                 ))
-                        ))
+                        )))
                     <option value="{{ $key }}" selected>{{ $value }}</option>
                 @else
                     <option value="{{ $key }}">{{ $value }}</option>
@@ -75,7 +85,7 @@
                 function initUntriggeredSelectFromArray() {
                     // trigger select2 for each untriggered select2 box
                     $('.select2_from_array').each(function (i, obj) {
-                        if($(obj).closest('.item.sample').length>0){
+                        if ($(obj).closest('.item.sample').length > 0) {
                             return;
                         }