Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Nested Multifield Loop not getting executed

Avatar

Avatar
Applaud 25
Level 2
Shaheena_Sheikh
Level 2

Likes

2 likes

Total Posts

96 posts

Correct Reply

1 solution
Top badges earned
Applaud 25
Applaud 5
Affirm 1
Validate 10
Validate 1
View profile

Avatar
Applaud 25
Level 2
Shaheena_Sheikh
Level 2

Likes

2 likes

Total Posts

96 posts

Correct Reply

1 solution
Top badges earned
Applaud 25
Applaud 5
Affirm 1
Validate 10
Validate 1
View profile
Shaheena_Sheikh
Level 2

21-05-2021

I have a dialog where there is nested multifield. In the nested multifield, there's dropdown.

-----

Details of the dialog:

Multifield

  Container (name = Parent)

     Multifield

          Container (name = Child)

              dropdown (class = cq-dialog-dropdown-showhide-multi)

------

Javascript code for looping :

(function ($, document, ns) {

   const A = function () {

         console.log("In A");

      $(this).find("[data-granite-coral-multifield-name='./Child'] .coral3-Multifield-item").each(function( index ) {
         console.log("In Loop");

      })

  };

  $(document).on("change", ".cq-dialog-dropdown-showhide-multi", function() {
      A();
  });

  $(document).on("dialog-ready", function() {
      A();
  });

})(Granite.$, document, Granite.author);

-------

Function A gets called once the dialog content has loaded (on opening the dialog).

Function A gets called when there is a change in dropdown value.

-------

Suppose if my parent multifield has 1 item and its child multifield has 2 items:

Func A gets called when the dialog is opened and "In A In Loop In Loop" gets printed in console. Now if I change the dropdown value, "In A" gets printed in console. The loop doesn't get executed even though the number of child items are still the same.

Not sure what exactly may be the issue. Please advice.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Applaud 25
Level 2
Shaheena_Sheikh
Level 2

Likes

2 likes

Total Posts

96 posts

Correct Reply

1 solution
Top badges earned
Applaud 25
Applaud 5
Affirm 1
Validate 10
Validate 1
View profile

Avatar
Applaud 25
Level 2
Shaheena_Sheikh
Level 2

Likes

2 likes

Total Posts

96 posts

Correct Reply

1 solution
Top badges earned
Applaud 25
Applaud 5
Affirm 1
Validate 10
Validate 1
View profile
Shaheena_Sheikh
Level 2

24-05-2021

Corrected the code line as below and the loop will start working fine:
$(this).find("[data-granite-coral-multifield-name$='Child'] .coral3-Multifield-item").each(function( index ) {

Answers (1)

Answers (1)

Avatar

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

551 likes

Total Posts

663 posts

Correct Reply

191 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

551 likes

Total Posts

663 posts

Correct Reply

191 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile
asutosh_jena
Level 10

22-05-2021

Hi @Shaheena_Sheikh 

 

You can use the Model class to achieve the functionality than doing all these iterations in JS. Why are you not using the Sling Models?