Nested multifield loop | Community
Skip to main content
Level 6
April 28, 2021
Solved

Nested multifield loop

  • April 28, 2021
  • 2 replies
  • 1266 views

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.
Best answer by Anudeep_Garnepudi

@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 )}; )};

2 replies

Anudeep_Garnepudi
Community Advisor
Anudeep_GarnepudiCommunity AdvisorAccepted solution
Community Advisor
April 28, 2021

@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 )}; )};
Level 6
May 7, 2021
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.
Nikhil-Kumar
Community Advisor
Community Advisor
April 28, 2021

@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/