These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How to make Reset button that resets selective fields only in LiveCycl

suewhitehead
Registered: Jun 3 2008
Posts: 232
Answered

I am a Beginner and want to know how to make my RESET FORM button skip a field when it resets the form. I can see how to do it in Acrobat, since a nice list is available on the Actions tab. I just uncheck the field(s) I do not want to reset. But how do I do it in LiveCycle 9?

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Start off by adding a regular button to your form. Then add some code to the click event to do the reset.

xfa.host.resetData("xfa.form.form1.myField1,xfa.form.form1.MyField2");

notice that the full hierarchy path is required for this function. This is called the SOM path, and you can find it at the top of the "Scripting" window when you click on a field in the design window.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

suewhitehead
Registered: Jun 3 2008
Posts: 232
Just to make sure I understand, if I have 30 fields on a form and I want to reset all of them except one, I would have to put the names of all 29 fields that I want reset in the javascript? There is not a quick way to just exclude one field?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Well, yes and no. This entry in the XML Form Object Model Reference states the input to "resetData" is:

Quote:
A valid string listing either the names or the equivalent reference syntax expressions of the fields to reset. The list entries are delimited by the “,” (comma) character. If the string is not present or empty, all the fields in the form are reset to their default value.
There is a whole reference on writing SOM expressions. So you can in fact write an expression that references more than one field, but I don't know about writing one that excludes a field. You can find this document here:

http://kb.adobe.com/selfservice/viewContent.do?externalId=330467&sliceId=2There is also another way to do this, and that's to write code to build the input to the function. I believe I already answered a question very much like this. Search the forum for posts using the word "resetData".

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

suewhitehead
Registered: Jun 3 2008
Posts: 232
I appreciate your help. I have seen some of your tutorial videos and they have been very helpful. My problem is that I have no scripting background. I found this answer in another post to the forum, but I just don't know what to do with it. Could you help just a little more?

"Next, since you are using a LiveCycle form you should use the reset function for LiveCycle JavaScript.

xfa.host.resetData();

Unfortunately, there isn't a function for resetting everything except a few fields. If there are too many fields to write it all in a single reset, and you can't group the non-reset fields into a subform, you'll have to write a function to do this.

Actually, it isnt' too bad. The XFA layout DOM has a function that returns a collection of all the fields on a page.

xfa.host.pageContent(pgNum,"field");

Use this function to walk through all fields on all pages to get the full SOM paths of all the fields, excluding of course the ones you don't want reset. Then just pass the final list into the "xfa.host.resetData()" function."

I don't understand how to use "xfa.host.pageContent(pgNum,"field");" Where do I put it or how do I run it to get the list of field names?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
In order to use these methods you're going to have to learn just a little bit about JavaScript.

The pageContent function returns a Collection object. This is a commonly used type of object in LiveCycle.

For example, to reset all the fields on page 1 except for one called "MyField" the code would look like this.

var cFldPaths = "";var oFldsOnPg1 = xfa.layout.pageContent(0,"field");for(var i=0;i<oFldsOnPg1.length;i++){if(i != 0)cFldPaths += ",";if(oFldsOnPg1.item(i).name != "MyField")cFldPaths += oFldsOnPg1.item(i).somExpression;}xfa.host.resetData(cFldPaths);

Place this code in a button and modify it to exclude your field. If the form has more than one page, the code will have to be modified to get fields form al the pages.

Good Luck,
Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

suewhitehead
Registered: Jun 3 2008
Posts: 232
Thanks so much Thomp. I had to discern that the subform was named Pg1 also. Once I changed mine to match, it worked!
Muntron
Registered: Dec 8 2008
Posts: 6
Besides resetting the data, I would like to have fields that have been dynamically (programatically) added to revert back. is this possible?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
What do you mean by "revert" back? Do you mean removed from the form? Were these fields added with the instance manager? If they were, then there is a removeInstance() fucntion that will deleted the fields from the form.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Muntron
Registered: Dec 8 2008
Posts: 6
Yes, I was trying to avoid having to call the instance manager. Since I know how many instances I originally placed in the form, I can remove any extra ones. I was just hoping for some magic :-).

By the way is there a way to query the subform to find out the initial number of instances? I do not need it this time, since I have two subforms which start with one instance each, but I can imagine more complicated situations. Besides, it would be better programming.

Thanks again.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, the instance manager has a "count" property, and each subform instance knows it's own index.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com

The Acrobat JavaScript Reference, Use it Early and Often
http://www.adobe.com/devnet/acrobat/javascript.php

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

disssg
Registered: Dec 10 2008
Posts: 12
Hi Thomp

Small help here please, How to stop extracting image field during "Merge data file into spread sheet"? When I extract all my form's data to excel inbetween each form record i can see 1000++ rubbish coding like "VBJHFJHDBDFBNDB VDVDNDFJ" look around I found those due to picture. once I remove picture from form and try all works find.

please help
Disssg
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Your question is off topic. Please start a new thread.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script