Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Resetting table rows to the inital count after pressing Reset Button

Avatar

Level 6

Hello,

I know this is a simple JavaScript, but how do you reset a table's row count to the initial count after pressing a Reset button?  Currently, I have 3 rows as the initial count (as indicated in the Binding tab), but if I go and add 2 addition rows (thereby bringing it to 5),  then press the reset button to reset the entire form, all the data clears as expected, but the row count says at 5 instead of defaulting back to the initial row count of 3.

I tried adding  xfa.layout.relayout(); to the rest button script to no avail.

I presume need to use a script to trigger the row count (something count == 3)...I just don't know what script to use.

Please advise.

Thanks.

7 Replies

Avatar

Level 10

I think you may need an xfa.form.remerge() instead of the xfa.layout.relayout().

Avatar

Level 6

Hmmm, that didn't work...thank you for your input though; I appreciate it!

I think I may have gotten it to work with:

Body4.JobExp._detail.count = 2;

Body4 = subform name

JobExp = table name

_detail = row

I just added it to the Reset button's click event.

S

Avatar

Former Community Member

This is the Javascript on my reset button now:

form1.BodyPage.ResetButton1::click - (JavaScript, client)
xfa.host.messageBox("Are you sure you want to erase ALL data on this form and start over?")
xfa.host.resetData();
xfa.form.remerge();
app.runtimeHighlight = false

I use the app. runtimeHighlight line to clear the red border on required items on a form reset.

Trying your solution but it doesn't seem to work for me.  Did you get this to work?

Avatar

Level 10

Hi,

What I have done in the past is to loop through the repeating instance until the count is back to what I want. The following is additional script in a reset button:

// loop through table and delete rows


while (Table1._Row1.count > 1)

{

     Table1._Row1.removeInstance(0);

}

Row1 in the repeating object and the underscore '_' is shorthand for instanceManager.

Hope that helps,

Niall

Avatar

Former Community Member

Bingo! That did the trick.

Niall you are awesome!

Avatar

Level 3

I have a follow-up to this. I have the table row reset working, but my issue is that if I say "no" when the reset dialog box comes up, it still resets the rows. How do I add to this to keep this from happening?

Avatar

Level 10

Are you using app.alert to get the yes/no answer?

var nButton = app.alert({

          cMsg: "Warning: You are about to reset the table. \n\nDo you want to continue?",

          cTitle: "Reset Table",

          nIcon: 1, nType: 2

});

if (nButton == 4) {

       put table reset code here

}