Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

User rearrange subform instances

Avatar

Level 4

What code do I use on buttons to allow the user to move instances of a subform up or down? In other words, make instance 3 instance 4, and make instance 4 instance 3.

7 Replies

Avatar

Level 10

Hi,

You would need to include two buttons in the "repeatingSubform" with javascript like this in the click event (you will need to change "repeatingSuform" for the name of your subform)

var nIndexFrom = repeatingSubform.index;    
if ((nIndexFrom + 1) < repeatingSubform.instanceManager.count)

     var nIndexTo = nIndexFrom + 1;   
     _repeatingSubform.moveInstance(nIndexFrom, nIndexTo);   
}   
else
{
     xfa.host.messageBox("This repeatingSubform can't be moved down since it already is the last one in the table.", "A title for your message box...", 1);
}

This moves the instance of the subform down. Similar script would be needed for the up button.

if (repeatingSubform.index != 0) 
{   
     var nIndexFrom = repeatingSubform.index;
     var nIndexTo = gdetail.index - 1;   
     _repeatingSubform.moveInstance(nIndexFrom, nIndexTo);   
}   
else
{   
     xfa.host.messageBox("This repeatingSubform can't be moved up since it already is the first one in the table.", "A title for your message box...", 1);
}

Good luck,

Niall

Avatar

Level 4

Niall to the rescue, again!  Thanks for your reply.

My subform situation is a little complicated. I have attached my form for you to look at.

To recreate:

open form

click "Edit to existing course"

click Page to add an instance of the page subform

click Page to add another instance

use "Move" buttons to rearrange them

When user adds an instance of the page subform, they are really adding an instance of the parent subform Pages. This is so as the child subforms, page, discussion, assessment, dropbox are added by the user, they show up in the order the user calls them.

So, the script for the "Move" buttons need to reference that specific instance of the Page subform. I have accomplished this on my other buttons by referencing this.parent on my buttons. It's not working this time, though.

Right now I have for "Move page up":

----- SBtemplate.Pages.page.geninfo.movepage.Button6[0]::click: - (JavaScript, client) -------------


if (xfa.form.SBtemplate.Pages(this.parent.parent.parent.parent.index)!= 0)

{  

     var nIndexFrom = xfa.form.SBtempate.Pages(this.parent.parent.parent.parent.index);

     var nIndexTo = gdetail.index - 1;  

     xfa.form.SBtemplate._Pages.moveInstance(nIndexFrom, nIndexTo);  

}  

else

{  

     xfa.host.messageBox("This repeatingSubform can't be moved up since it already is the first one in the table.", "A title for your message box...", 1);

}

and for "Move page down"

----- SBtemplate.Pages.page.geninfo.movepage.Button6[1]::click: - (JavaScript, client) -------------


var nIndexFrom = xfa.form.SBtemplate.Pages(this.parent.parent.parent.parent.index);  

if ((nIndexFrom + 1) < xfa.form.SBtemplate.Pages.instanceManager(this.parent.parent.parent.parent.count))

{

     var nIndexTo = nIndexFrom + 1;  

     xfa.form.SBtemplate._Pages.moveInstance(nIndexFrom, nIndexTo);  

}  

else

{

     xfa.host.messageBox("This repeatingSubform can't be moved down since it already is the last one in the table.", "A title for your message box...", 1);

}

Thanks for your help.

Avatar

Level 10

Hi,

Sorry, not making too much progress!!

The example I set out was for a repeating row in a table.

I have looked at your script and it is a complex set up. I have changed the reference to instanceIndex, which should work for repeating subforms. However it is returning "0" each time.

It's late here, so I am going to take a break. Hopefully something will drop into place in the meantime.

Also in the script I posted there was a reference to "gdetail" this was from my form and I should have changed this to "repeatingSubform". I have changed it in the form, but that is not the main problem.

Later,

Niall

Avatar

Level 4

Hello Niall and other community members. I am still trying to figure this out. If anyone can offer suggestions or solutions, I would greatly appreciate it!

Thanks!

Tianna

Avatar

Level 10

Hi Tianna,

Sorry but I have not been able to crack this as yet. I am going to be out of the office for the next few days, but I will try and have a look again.

In the meantime hopefully someone may be able to solve it sooner.

Good luck,

Niall

Avatar

Level 10

Hi Tianna,

I am really glad you got this sorted with Paul's help - Problem solved!!!

Good luck,

Niall