Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

xfa.form.remerge(); not setting form to original state ?? Removeinstance issue?

Avatar

Level 1

I am a novice form developer that cannot figure out how to get "xfa.form.remerge();" to work correctly. I have a form that contains three subforms with repeating instances.  My goal is to create a reset button that will present a dialog box to the user to confirm the reset.  If the user select "yes" I want all data cleared and the entire form set to its initial state.  I am using the script below which clears the data but doesn't reset the subform instances back to its original state

On click*

var nButton = app.alert({
cMsg:"Warning: You are about to reset the order form data. \n\nDo you want to continue?",
cTitle: "You have clicked the reset button",
nlcon: 1, nType:2
});

if (nButton ==4)
{
xfa.host.resetData();
xfa.form.remerge();
}


The second obstacle I am trying to figure out is with the remove button within my repeating subforms.  My current button works great except when there is only one instance with data. If I only have one instance with data the remove button does nothing.  I am hoping to find way to have the "remove" button reset the current instance to initial state if only one instance is present but delete if more than one instance has been created

On click*

this.resolveNode('limited._order').removeInstance(this.parent.index);
if (xfa.host.version < 😎 {
     xfa.form.recalculate(1);

}

Any assistance will be greatly appreciated, below is a link to a sample of my form for reference

Sample

12 Replies

Avatar

Level 10

The resetData function will only clear out the fields ...it will not reset the state of the form. The remerge function will merge the data dom and the template dom again ...this will have no bearing on what you are trying to do. You can use the resetdata function to clear the fields ooy (this will clean the data dom as well) but you will have to write code to programmatically reset the form to its original state (i.e. remove all subforms that were added)

Paul

Avatar

Level 1

pguerett-

Thank you for the assisance, can you provide an example of how might script a command to remove all subform instances.  Do you know of a way to possibly reset the subform presence or reset the entire form to it's original state?

Besgt Regards!

Avatar

Level 10

Hey Paul, I've used the remerge function to get a form back to its initial state after doing a resetData. I've had pretty good luck with it except for a recent form in which I was using John Brinkman's mandatory routines.

I'd like to know if there's a better way too!

I was wondering about using the Acrobat/Reader "Revert" menu item but wasn't sure about the implications if someone was filling from inside a web browser.

Avatar

Level 10

I do not know of a way other than coding it .....let me check into this but I will not be able to get an answer back until tomorrow.

Paul

Avatar

Level 10

Hi Paul, were you able to find out any more info on this?

Avatar

Level 10

I got the answer and forgot to post it ...thanks for reminding me.

By clearing the datadom of all data and resetting the root node you are forcing a remerge and the form will return to its original state (for the subform instances anyways). I have included a sample. Make sure that you change the root node in the loadXML statement to match your root node in your form hierarchy otherwise your Dom will get messed up and your bindings will no longer work.

Paul

Avatar

Level 10

I'd tried a slightly different version of that before but it didn't help with the recent problem I had using John's mandatory scripts.

The one I found in a forum was xfa.datasets.data.loadXML(newXML,1,1); instead of xfa.datasets.data.loadXML("<form1/>", true, true);

What happens is that after Reader Extending and doing a reset with remerge() (or the loadxml) I'd get a big string of errors from all the required fields. After you click OK on the error dialogue it all works fine but I couldn't figure out a way to get around it.

Avatar

Level 10

Well I do not know what the newXML is (must be a javascript var) so depending on what that was set to woudl determine if this woudl work or not. Not setting the proper node sure woudl mess things up though.

Paul

Avatar

Level 10

Oops, ya didn't have the whole thing in there...

//substituting 'MYFORM' with your top-level form name...

var newXML = "<?xml version='1.0' encoding='UTF-8'?><MYFORM></MYFORM>";

xfa.datasets.data.loadXML(newXML,1,1);

Avatar

Level 10

Yours is pretty much the same as mine ....I didn't try it with Reader Extensions etc ....like you did until now and it worked fine ...can you try it on your end and validate?

Th eonly difference is my xml did not have the processing instruction .....not a big deal as far as I am concerned.

Paul

Avatar

Level 10

Both the remerge and the two different loadxml scripts work fine when the form is Extended if you are using the built-in mandatory settings.

Avatar

Level 4

Hey Paul!

Can this be done on a specific subform instead of the whole form?  so where we have <form1/> is there a way to put the submform info?

thanks!
Jodi