Nested multifield loop | Community
Skip to main content
Level 6
Apr 28, 2021 4:56 AM UTC
Solved

Nested multifield loop

I have a nested multified and I need to loop through the inner multifield items also. For outer multifield I was using :

$(".coral3-Multifield-item").each(function( index ) {//body}

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Anudeep_Garnepudi
Anudeep_GarnepudiAccepted solution
New Participant
Apr 28, 2021 6:47 AM UTC

@shaheena_sheikh 

Target the parent/root multifiled using multifiled name like below.

$("[data-granite-coral-multifield-name='./multifield-name'] .coral3-Multifield-item").each(function( index ) { //Parent multifield items loop $(this).find(".coral3-Multifield-item").each(function( index ) { //Child multifiled items loop )}; )};

3 replies

Nikhil-Kumar
New Participant
Apr 28, 2021 7:39 AM UTC

@shaheena_sheikh -  You need to target the specific class and use coral Ui in jquery. One example that you can consider is : https://aemsimplifiedbynikhil.wordpress.com/2018/07/29/multifield-and-dialog-data-in-jquery/ 

Translate
Anudeep_Garnepudi
Anudeep_GarnepudiAccepted solution
New Participant
Apr 28, 2021 6:47 AM UTC

@shaheena_sheikh 

Target the parent/root multifiled using multifiled name like below.

$("[data-granite-coral-multifield-name='./multifield-name'] .coral3-Multifield-item").each(function( index ) { //Parent multifield items loop $(this).find(".coral3-Multifield-item").each(function( index ) { //Child multifiled items loop )}; )};
Translate
Level 6
May 7, 2021 7:42 AM UTC
I am only using the code for outer loop and I have a console log within the loop. I have a parent multifield item, and it has 2 child items. The console log is printing 3 times (1 parent + 2 child item). Even though the outer loop is for parent and should only run once.
Translate