]> _ Git - cubist_cms-back.git/commitdiff
wait #5674 @0:10
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 10 Jan 2023 19:03:29 +0000 (20:03 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 10 Jan 2023 19:03:29 +0000 (20:03 +0100)
src/app/Magic/Fields/SelectFromArray.php
src/resources/views/fields/select2_from_array.blade.php

index e09be70507d80a00a4cfb65970293fc8cfa50525..c2e55a299a504f4f28cb994c4f481b875d609b31 100644 (file)
@@ -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()
index da87ff6724d97bde05d17b421d4389ec14a94d7e..2e29e87287e394373780d7b8cc5f09ecd2359984 100644 (file)
@@ -71,10 +71,15 @@ if($ajax){
     @endif
 </select>
 
+@if($field['show_selected_option'])
+    <p class="help-block">{{__('Valeur actuelle : ')}} <span class="selectFromArrayCurrentValue"></span></p>
+@endif
 {{-- HINT --}}
 @if (isset($field['hint']))
     <p class="help-block">{!! $field['hint'] !!}</p>
 @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();
             }
         </script>
     @endpush