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.
URL: http://forums.planetpdf.com/forum_posts.asp?TID=1624
Printed Date: 27 Jun 2019 at 11:46am
Software Version: Web Wiz Forums 11.10 - http://www.webwizforums.com


Topic: Validation script?
Posted By: Maureen
Subject: Validation script?
Date Posted: 31 Jul 2015 at 4:00pm
hello
 
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



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

   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.

Regards,
morrison


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);
oField1.setFocus();
}

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 - http://www.webwizforums.com
Copyright ©2001-2017 Web Wiz Ltd. - https://www.webwiz.net