]> _ Git - cubist_cms-back.git/commitdiff
wip #5127 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 25 Feb 2022 18:41:18 +0000 (19:41 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 25 Feb 2022 18:41:18 +0000 (19:41 +0100)
src/app/Magic/Fields/SelectFromArray.php
src/public/bunchmultiple/bunchmultiple.js
src/resources/views/fields/select2_from_array.blade.php

index 9161da8702f8bd3ab0e13757256b6e65f586884a..a6a795ef805b261e1eb59d4d1c946ff6f2f013b8 100644 (file)
@@ -40,12 +40,12 @@ class SelectFromArray extends Field
             $data = ['results' => $results, 'pagination' => ['more' => false]];
             $hash = hash('sha256', print_r($data, true));
             $name = $hash . '.json';
-            $dir = \Cubist\Util\Files\Files::mkdir(public_path('select2'));
+            $dir = \Cubist\Util\Files\Files::mkdir(storage_path('select2'));
             $file = $dir . '/' . $name;
             if (!file_exists($file)) {
                 file_put_contents($file, json_encode($data));
             }
-            $this->setAttribute('ajax', $name);
+            $this->setAttribute('ajax', $hash);
         }
     }
 
index dd53a0133276f8efff8bf2547500812f0cbe18f0..621c1dade7f05192e9039657a79c980485e10570 100644 (file)
 
                     if (input.length === 0) {
                         input = form.find('[name="' + form.data('bmid') + '___' + varname + '"]');
-                        console.log(input);
                     }
                     var res = $(input).val();
 
index 2f3eaa78d429315817ac1598027f0a8c3d24f097..f9232443815f3e8904c51a38b71f77bf36c88cf7 100644 (file)
@@ -31,7 +31,7 @@
     style="width: 100%"
     @include('crud::fields.inc.attributes', ['default_class' =>  'form-control select2_from_array'])
     @if (isset($field['allows_multiple']) && $field['allows_multiple']==true)multiple @endif
-    @if(isset($field['ajax']) && $field['ajax']) data-ajax="{{$field['ajax']}}" @endif
+    @if($ajax) data-ajax="{{$field['ajax']}}" @endif
 >
     @if (isset($field['allows_null']) && $field['allows_null']==true)
         @if($is_null)
                         var options = {
                             theme: "bootstrap"
                         };
-                        if ($(this).is(['data-ajax'])) {
-                            options.ajax = {url: $(this).data('ajax'), dataType: 'json'};
+                        console.log($(this));
+                        if ($(this).is('[data-ajax]')) {
+                            options.ajax = {
+                                url: '{{backpack_url('select2')}}' +'/'+ $(this).data('ajax'),
+                                dataType: 'json'
+                            };
                         }
 
                         if (!$(obj).hasClass("select2-hidden-accessible")) {
+                            console.log(options);
                             $(obj).select2(options);
                         }
                     });