From a63ca8215146f310d43c532944ef6bf43579a0e7 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 6 Sep 2019 15:32:27 +0200 Subject: [PATCH] wip #3010 @1 --- src/app/Magic/EntityData.php | 2 +- .../views/fields/select2_from_array.blade.php | 43 +++++++++---------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/app/Magic/EntityData.php b/src/app/Magic/EntityData.php index 1e623e0..0956511 100644 --- a/src/app/Magic/EntityData.php +++ b/src/app/Magic/EntityData.php @@ -126,7 +126,7 @@ class EntityData implements \ArrayAccess $res = $res[App::getLocale()]; } - if (!$res) { + if (null === $res) { return $default; } return $res; diff --git a/src/resources/views/fields/select2_from_array.blade.php b/src/resources/views/fields/select2_from_array.blade.php index 351faef..54223bf 100644 --- a/src/resources/views/fields/select2_from_array.blade.php +++ b/src/resources/views/fields/select2_from_array.blade.php @@ -1,5 +1,21 @@ @php - $is_null=null===old(square_brackets_to_dots($field['name'])) && (isset($field['value']) && null===$field['value']); + $o=$field['value'] ?? old(square_brackets_to_dots($field['name'])); + + $is_null=null===$o; + if(!function_exists('select2_from_array_selected')){ + function select2_from_array_selected($key,$o){ + if(null===$o){ + return false; + } + if(!is_array($o)){ + return $o==$key; + } + if(is_array($o)){ + return in_array($key,$o); + } + return false; + } + } @endphp @@ -22,27 +38,10 @@ @if (count($field['options'])) @foreach ($field['options'] as $key => $value) - @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'] && null !== $field['value'] )|| ( - is_array($field['value']) && - in_array($key, $field['value']) - ) - )) || - (isset($field['default']) && - ($key == $field['default'] || ( - is_array($field['default']) && - in_array($key, $field['default']) - ) - ) - )) - ))) + @php + $selected=select2_from_array_selected($key,$o); + @endphp + @if($selected) @else -- 2.39.5