]> _ Git - cubist_cms-back.git/commitdiff
wip #6250 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 6 Sep 2023 19:56:02 +0000 (21:56 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 6 Sep 2023 19:56:02 +0000 (21:56 +0200)
src/resources/views/when.blade.php

index 9ef1945ec16c61e844869beb67261af79540ea21..e437a47b2d0de4ad246c732d9bf7619c8bb2b80e 100644 (file)
@@ -1,6 +1,7 @@
 @push('crud_fields_scripts')
     <script type="text/javascript">
         jQuery('document').ready(function ($) {
+
             var triggersWhenChange = function (f) {
                 var form;
                 var prefix = '';
@@ -23,6 +24,7 @@
                 });
 
                 $(form).find('[data-when]').removeClass('when-visible').each(function () {
+                    var element = $(this);
                     if ($(this).data('when-normalized') === undefined) {
                         $(this).data('when-normalized', normalizeWhen($(this).data('when')));
                     }
                     var match = true;
                     var order = 1000;
                     $.each(when, function (property, conditions) {
-                        var fname = prefix + property;
-                        var e = $(form).find('[name="' + fname + '"]');
+                        var e = findCloserInput(element, property);
+                        if ($(element).is('[bp-field-name]') && $(element).attr('bp-field-name').indexOf('area_1') >= 0) {
+                            console.log(property, element, e);
+                        }
                         var val;
+                        if ($(e).length === 0) {
+                            match = false;
+                            return false;
+                        }
                         if ($(e).length === 1) {
                             try {
                                 val = $(e).val().toString();
@@ -52,6 +60,7 @@
                                 }
                             }
                         }
+
                         var matchproperty = false;
                         $.each(conditions, function (k, condition) {
                             if (condition.id === val) {
                 return value && typeof value === 'object' && value.constructor === Object;
             }
 
+            function findCloserInput(element, inputName) {
+
+                let siblings = $(element).siblings('[data-name="' + inputName + '"]');
+                if (siblings.length === 0) {
+                    let parent = $(element).parent();
+                    if (parent === null || $(parent).length === 0) {
+                        return null;
+                    }
+                    return findCloserInput(parent, inputName);
+                }
+                let res = $(siblings).find('[name="' + inputName + '"]');
+                if (res.length === 0) {
+                    res = $(siblings).find('[name$="___' + inputName + '"]');
+                }
+                return res;
+            }
+
         });
 
     </script>