jqh 4 роки тому
батько
коміт
4c2157901c

+ 12 - 2
resources/views/form/select-script.blade.php

@@ -38,7 +38,10 @@
         var urls = '{!! $loads['urls'] !!}'.split('^');
 
         var refreshOptions = function(url, target) {
+            Dcat.loading();
+
             $.ajax(url).then(function(data) {
+                Dcat.loading(false);
                 target.find("option").remove();
                 $(target).select2({
                     data: $.map(data, function (d) {
@@ -54,14 +57,21 @@
         $(document).on('change', selector, function () {
             var _this = this;
             var promises = [];
+            var values = [];
+
+            $(this).find('option:selected').each(function () {
+                if (String(this.value) === '0'|| this.value) {
+                    values.push(this.value)
+                }
+            });
 
             fields.forEach(function(field, index){
                 var target = $(_this).closest('.fields-group').find('.' + fields[index]);
 
-                if (_this.value !== '0' && ! _this.value) {
+                if (! values.length) {
                     return;
                 }
-                promises.push(refreshOptions(urls[index] + (urls[index].match(/\?/)?'&':'?') + "q="+ _this.value, target));
+                promises.push(refreshOptions(urls[index] + (urls[index].match(/\?/)?'&':'?') + "q="+ values.join(','), target));
             });
 
             $.when(promises).then(function() {});

+ 13 - 2
resources/views/scripts/select.blade.php

@@ -44,13 +44,24 @@
         $(document).off('change', selector);
         $(document).on('change', selector, function () {
             var target = $(this).closest('{{ $load['group'] ?? '.fields-group' }}').find(".{{ $load['class'] }}");
+            var values = [];
 
-            if (String(this.value) !== '0' && ! this.value) {
+            $(this).find('option:selected').each(function () {
+                if (String(this.value) === '0'|| this.value) {
+                    values.push(this.value)
+                }
+            });
+
+            if (! values.length) {
                 return;
             }
             target.find("option").remove();
 
-            $.ajax("{!! $load['url'].(strpos($load['url'],'?')?'&':'?') !!}q="+this.value).then(function (data) {
+            Dcat.loading();
+
+            $.ajax("{!! $load['url'].(strpos($load['url'],'?')?'&':'?') !!}q="+values.join(',')).then(function (data) {
+                Dcat.loading(false);
+
                 $.map(data, function (d) {
                     target.append(new Option(d.{{ $load['textField'] }}, d.{{ $load['idField'] }}, false, false));
                 });