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.

Reset all fields in a repeating subform and restore instance count back to 1

Avatar

Level 6

I've played around with a few different scenarios and able to achieve parts of the solution, but not there fully.

Whenever I use.....xfa.host.resetData("xfa.form.form1..."); ...it only resets the fields in the 1st instance of the repeating subform. So if I have 3 instances, it only resets instance 1.

Currently, the subform is set to an initial count of 1, and additional instances are added via an "Add" button.

Thus, I'm looking for a solution that will not only reset all content within a "specific" subform (not entire form), AND restore the instance count back to 1.

Thank you in advance!!!

7 Replies

Avatar

Level 10

Here I made a script object that works perfectly for reseting form... the only thing is that objects that were hidden initially in the form will not return hidden...

https://drive.google.com/file/d/0Bz8yb5apn8y4a1RUY1R0R0RSbWs/edit?usp=sharing

The method getExpressions in my script object myForm is to remove all instances of ROWS, all values from fields that are children of the subform specified

You can send the subform that you want it to be reset and also you can send names of objects that should not be reset inside the subform...

If you have any request, or question about it, you're free to ask!

Avatar

Level 10

Oh, too have this method work, you would have to change your Subform instances to Rows instead.... if you keep subforms you will have to reset the instances by yourself

Avatar

Level 6

Thanks Robert - I reviewed your file. Much appreciated.

Is there an easier approach? Seems like a lot of complex scripting for what I'm simply looking to do.

I just want to reset a specific subform's data instead of clearing the entire form. I can handle the part of resetting the instance count back to 1.

Avatar

Level 10

well, actually if you want to reset specific fields in the form, you have to write all the som expressions of the objects you want to reset in the form into the method resetData();

the method I gave you is made to acquire all those somExpressions and reset all fields you want, all you need to do is remove the exception fields in the tabExceptions if you have no field in the form or subform you don't want to reset...

and just send the subform as parameter in the method and it will return all fields you want to reset...

that's what you want to do, and you have it all done, all you need to do is send the subform object as parameter...

otherwise you can write your own script to go reset each field one by one

Avatar

Level 6

Here's a link to a basic file: https://www.dropbox.com/s/w6wl4qwpse4b23t/Reset%20Repeating%20SubForm.pdf

I know this is incorrect, but I was hoping I could use something like.....xfa.host.resetData("xfa.form.form1.Page1.Row[*]");.....to reset a specific/entire subform group that has multiple instances. However, the script ONLY clears the first instance.  WHat I think needs to happen is there needs to a script that loops through the named subform to gather all instances then somehow pass the count as a parameter to the resetData script.

Avatar

Level 6

I played around with this a little further and found this simple, modified, approach works:

*Partial credit to Niall Donovan for use of "while" script in a different post

//Remove instances of subform until only 1 remains

while (Page1._Row.count > 1)

{

Page1._Row.removeInstance(0);

}

//Reset subform

xfa.host.resetData("xfa.form.form1.Page1.Row");

Avatar

Level 2

Brilliant! Worked perfectly. Much obliged.