From fd3fbe639e0628321d8efb4af16c11b6ee837cb4 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 10 Jan 2023 20:03:29 +0100 Subject: [PATCH] wait #5674 @0:10 --- src/app/Magic/Fields/SelectFromArray.php | 4 +++- .../views/fields/select2_from_array.blade.php | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/app/Magic/Fields/SelectFromArray.php b/src/app/Magic/Fields/SelectFromArray.php index e09be70..c2e55a2 100644 --- a/src/app/Magic/Fields/SelectFromArray.php +++ b/src/app/Magic/Fields/SelectFromArray.php @@ -24,9 +24,11 @@ class SelectFromArray extends Field protected $_ajax = true; protected $_allowsHTML = false; + protected $_showSeletedOption = false; + public function getDefaultAttributes() { - return array_merge(parent::getDefaultAttributes(), ['options' => $this->getOptions(), 'options_aliases' => $this->_options_aliases, 'allows_null' => $this->_allowNull, 'allows_multiple' => $this->_multiple, 'ajax' => $this->_ajax, 'allows_html' => $this->_allowsHTML]); + return array_merge(parent::getDefaultAttributes(), ['options' => $this->getOptions(), 'options_aliases' => $this->_options_aliases, 'allows_null' => $this->_allowNull, 'allows_multiple' => $this->_multiple, 'ajax' => $this->_ajax, 'allows_html' => $this->_allowsHTML, 'show_selected_option' => $this->_showSeletedOption]); } protected function _postSetAttributes() diff --git a/src/resources/views/fields/select2_from_array.blade.php b/src/resources/views/fields/select2_from_array.blade.php index da87ff6..2e29e87 100644 --- a/src/resources/views/fields/select2_from_array.blade.php +++ b/src/resources/views/fields/select2_from_array.blade.php @@ -71,10 +71,15 @@ if($ajax){ @endif +@if($field['show_selected_option']) +

{{__('Valeur actuelle : ')}}

+@endif {{-- HINT --}} @if (isset($field['hint']))

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

@endif + + @include('crud::fields.inc.wrapper_end') {{-- ########################################## --}} @@ -101,8 +106,19 @@ if($ajax){ initUntriggeredSelectFromArray($); }); initUntriggeredSelectFromArray($); + + $(document).on('change', '.select2_from_array', function () { + showSelectedValue(); + }); }); + function showSelectedValue() { + $('.selectFromArrayCurrentValue').each(function () { + let v = $(this).closest('.form-group').find('select').val(); + $(this).text(v); + }); + } + function initUntriggeredSelectFromArray($) { // trigger select2 for each untriggered select2 box $('.select2_from_array:not(.select2-hidden-accessible)').each(function (i, obj) { @@ -126,6 +142,7 @@ if($ajax){ } $(obj).addClass('init').select2(options); }); + showSelectedValue(); } @endpush -- 2.39.5