Expand my Community achievements bar.

New to the product - question about validating multiple fields as a group

Avatar

Level 1

I have a static form that I'm building from a word document.  Part of that form requires a person to fill any 3 out 5 text fields.

  1. Since it looks like scripts are applied on a field by field basis, is it possible to have a script that encompasses multiple fields? 
  2. Would any script need to be applied to each field in turn?
  3. Assuming the answer to question 1 is a yes, how would you script it to require x number of fields out of a total of y to have some sort of content in order to validate?

I'm pretty familiar with JavaScript and am looking at the Scripting reference guides but was hoping for a helping hand to get me there quicker as I'm in a bit of a time crunch - doing 18 forms with validation and database connectivity by January 15 certainly qualifies in my book.

I would assume you'd do something like this but am unsure of the syntax...

Get values of each field

Set a valid counter variable for the number of fields with content

If field 1 is not empty, increment the valid counter

(rinse and repeat)

if the valid counter is less than 3 throw an error message

Many thanks in advance for any help offiered

1 Reply

Avatar

Level 4

1). Yes, scripting within Livecycle can be for a single field or even static text, images and other artifacts within the PDF. Really anything, within Adobe's reason, when it comes to scripting.

2). It depends on what you want to do. Things like field validations, calculations and other instances where fields are tied togther really dictate how the script runs.

3). Fields that have calculations or validations with them work in the same, I believe. So for example I have a PDF that I made that is an Excel-type sheet that contains a few hundred cells and every single one has some type of validation or calculation associated with it. I generally run the calculations/validations from the user inputting the data and then after that the script runs, but again, it really dpeneds on what you are doing and with what, so answering some of your questions are a bit difficult.

Javascrip/Formcalc are wonderful tools within PDF, but don't forget the Action Builder (Tools -Action Builder). It is a set of preloaded actions that are turn-key. Just select the cells that will have the action and select the result you want from the preloaded list of actions, using those actions can get you very far, and most of all; they are quick to implement without researching code. So for example, you could use the Action Builder to create an action that checks certain fields and if they are null to return a 1 value to a specific numericField (these could be hidden). Then have a "total" numericField (this would be your counter) that adds all of those fields with the 1 in it. Then create another Action Builder for that "total" numericField and if it is less than 3, display a message box that is a warning.