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

Processing only visible fields on a form

mark123
Registered: Mar 18 2008
Posts: 10

Hello all -

I'm trying to adapt Stefan Cameron's "Process All Fields" script (found here: http://forms.stefcameron.com/2006/06/26/process-all-fields/) to validate only VISIBLE fields on the form, instead of all fields, prior to submitting.

He includes a sample script that searches a form for non-filled (empty) mandatory fields when the Submit button is clicked. If such fields are found, they'll be highlighted and an error message will be displayed. Otherwise, the Email Submit dialog will open.

His sample works like a charm EXCEPT when fields are wrapped in a subform and the subform presence property is set to "invisible". His script still flags the non-filled mandatory fields even though they are not displayed or visible on the form. I'm using subforms to hide or show fields based on user interaction, so I can't just make the fields optional. If they are visible, they are mandatory.

Unfortunately, I haven't had much luck. Is there a way to flag only the visible non-filled mandatory fields?

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I don't think that there is a property or attribute specifically for this. but, it's easy enough to walk up the subform tree to find out if any of the parents are invisible. Here's a function that will work for this. The input parameter is a field object.

function isVisible(oFld)
{
var bVis = true;
var nxtFld = oFld;
while(nxtFld.name != "form")
{
if(nxtFld.presence != "visible")
{
bVis = false;
break;
}
nxtFld = nxtFld.parent;
}
return bVis;
}

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

mark123
Registered: Mar 18 2008
Posts: 10
Hi Thom -

Thanks for the response and function, but I'm not quite sure how to implement it.

I tried adding it as a second condition on the following if statement from the click event of my submit button, but I don't think I got the syntax quite right:

// highlight required fields
if (ScriptObject.HighlightRequiredFields(form1, true) > 0) && (ScriptObject.isVisible.bVis = true)
{
ScriptObject.bFieldsHighlighted = true;
RemoveHighlight.presence = "visible";

app.alert("Some mandatory fields weren't filled.");
}
else
{
// OK to submit
EmailSubmitButton1.execEvent("click");
}

Am I on the right track? If not can you set me straight?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
It looks like you've placed it correctly in a Script Object, but it's being called incorrectly. It's a fuction, so you have to use the "()" notation.

if( ScriptObject.isVisible( someFieldObject ))
{
....
}

The input to this function is a field object. The function returns false if the "presense" of the field, or any of it's parents, is not "visible"

It has to be run on each field of interest. But you could easily modify it to look at a set of fields.

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