Print Page | Close Window

Validation script?

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
Printed Date: 16 Sep 2019 at 5:40pm
Software Version: Web Wiz Forums 11.10 -

Topic: Validation script?
Posted By: Maureen
Subject: Validation script?
Date Posted: 31 Jul 2015 at 4:00pm
I'm not sure  if it's a validation javascript I need, but this is my question
In field1=date . Field 2=value. If field 1 is empty, but field2 is filled in, a popup must appear with a tekst like "Set a date in field1". Or even better is, when Field2 is filled in, Field1 become a mandatory field.
Can I get help for this?
Thank you

Posted By: morrison
Date Posted: 13 Oct 2015 at 5:05pm

   I am thinking that you could use a custom calculation script in Field 2.

if(event.value != "")
 this.getField("field1").required = true;

If you want to add a popup message to that, you would just add the app.alert line:

if(event.value != "")
 this.getField("field1").required = true;
 app.alert("Set a date in field1",1);

If you would rather use the "stop" symbol instead of the warning symbol, replace the 1 with 0.


Posted By: gkaiseril
Date Posted: 13 Oct 2015 at 5:34pm
I would not use a calculation script since this could add significant overhead to the form since each time a field used in any calculation in the form would cause the calculation to be run. Adobe provides a tab for the form field called "Validation" just for such a task. I this case I might use 2 validation scripts, one for the date field and the other for the text field.

I would set the field up with the "Field 2" set to read only and then unlock that field only when "Field 1" is not empty. This would require "Field 1" be completed before "Field 2". One may also need to consider the case where "Field 1" has been completed and an entry has been made in "Field 2" and then "Field 1" is cleared.

Field 1 validation script:

var oField2 = this.getField("Field 2");
if(event.value != "") {
// unlock Field 2;
oField2.readonly = false;
if(event.value == "" && oField2 != "") {
// Field 1 has been cleared, clear Field 2;
oField2.value = "";

Field 2 validation script:

var oField1 = this.getField("Field 1");
if(event.valule != "" && oField1.valueAsString = "") {
app.alert("Field 1 must be completed before Field 2 can have a value", 1, 0);

As for the "required" property of a field, unless you are submitting the form to a scripted web page or emailing the form, there will be no checking for the required form fields unless you provide some sort of script. This would also apply to printing of the form.

Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 -
Copyright ©2001-2017 Web Wiz Ltd. -