From: Vincent Vanwaelscappel Date: Wed, 24 Mar 2021 16:31:23 +0000 (+0100) Subject: wip #4370 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=113a21fd276bf1d80e7e2ff37e7a6a62d2c36218;p=cubist_cms-back.git wip #4370 @1 --- diff --git a/src/app/Magic/Fields/SelectFromArray.php b/src/app/Magic/Fields/SelectFromArray.php index 8f68334..d571dac 100644 --- a/src/app/Magic/Fields/SelectFromArray.php +++ b/src/app/Magic/Fields/SelectFromArray.php @@ -24,6 +24,14 @@ class SelectFromArray extends Field return array_merge(parent::getDefaultAttributes(), ['options' => $this->getOptions(), 'options_aliases' => $this->_options_aliases, 'allows_null' => $this->_allowNull, 'allows_multiple' => $this->_multiple]); } + protected function _postSetAttributes() + { + parent::_postSetAttributes(); + if ($this->getAttribute('default') !== null && $this->getAttribute('allows_null')) { + $this->setAttribute('allows_null', false); + } + } + public function getOptions() { return $this->_options; diff --git a/src/resources/views/fields/select2_from_array.blade.php b/src/resources/views/fields/select2_from_array.blade.php index a0dcdaf..d482294 100644 --- a/src/resources/views/fields/select2_from_array.blade.php +++ b/src/resources/views/fields/select2_from_array.blade.php @@ -1,5 +1,5 @@ @php - $o=$field['value'] ?? old(square_brackets_to_dots($field['name'])); + $o=$field['value'] ?? old(square_brackets_to_dots($field['name']))??$field['default']; $is_null=null===$o; if(!function_exists('select2_from_array_selected')){ @@ -20,40 +20,40 @@ @include('crud::fields.inc.wrapper_start') - - 'form-control select2_from_array']) + @if (isset($field['allows_multiple']) && $field['allows_multiple']==true)multiple @endif +> - @if (isset($field['allows_null']) && $field['allows_null']==true) - @if($is_null) - - @else - - @endif + @if (isset($field['allows_null']) && $field['allows_null']==true) + @if($is_null) + + @else + @endif + @endif - @if (count($field['options'])) - @foreach ($field['options'] as $key => $value) - @php - $selected=select2_from_array_selected($key,$o); - @endphp - @if($selected) - - @else - - @endif - @endforeach - @endif - - - {{-- HINT --}} - @if (isset($field['hint'])) -

{!! $field['hint'] !!}

+ @if (count($field['options'])) + @foreach ($field['options'] as $key => $value) + @php + $selected=select2_from_array_selected($key,$o); + @endphp + @if($selected) + + @else + + @endif + @endforeach @endif + + +{{-- HINT --}} +@if (isset($field['hint'])) +

{!! $field['hint'] !!}

+@endif @include('crud::fields.inc.wrapper_end') {{-- ########################################## --}}