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

How to validate number of repeating elements in LiveCycle Form?

tarekahf
Registered: May 1 2008
Posts: 91
Answered

I have created a PDF Form using LiveCycle Desinger 7.1.

This form has Dynamic Repeating Elements and each one will have a [+] button the add a new element, and [-] button to remove the current one.

The repeating element has Min validation value of 1.

If the user click on [-] and there is one element, he will get script error that the element cannot be deleted since the minimum is 1.

I want to write validation to check the number of elements in the repeating subform, and tried this one, but not working:

JavaScript on MoustUp Event of the [-] button:

if (this.parent.nodes.length <= 1)
{
app.alert("You cannot delete this element.")
} else {
//
// the code to delete the element is working fine.
//
}

Please help.

Tarek.

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Each element has several sub-nodes that are unrelated to the visible elements on the form, so "nodes" is the wrong thing to look at when trying to determine the number of dynamic subform instances. The right place to look is the instance manager for the repeated subform.

For example if the repeated subform is named "ItemDetail" then this code can be used in any element inside the subform.

_ItemDetail.count

Where the underscore is shorthand for the instance manager and "count" is the number of existing intances of that subform. This code is equivalent to:

ItemDetail.instanceManager.count

A simple way to handle the delete subform button is to place this code in the "initialize" event for the button

if(_ItemDetail.count > 1)this.presence = "visible";elsethis.presence = "invisible";

This code hides the delete button if there is only one instance of the "ItemDetail" subform.

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

tarekahf
Registered: May 1 2008
Posts: 91
thomp,

Yes ! This is great. I will try it and I am sure it will work.

Note: I hope you could subscribe to the other thread about Dynamic change of Object Types on LiveCycle Form during runtime. I have started to find a solution, and I will decompose the problem into smaller parts to make it easier to work with. I just want you to watch the thread and make sure that I am going in the right direction.

Tarek.