Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Validation script?
  FAQ FAQ  Forum Search   Register Register  Login Login

Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Validation script?

 Post Reply Post Reply
Maureen View Drop Down
New Member
New Member

Joined: 09 Jun 2015
Location: Netherlands
Points: 24
Post Options Post Options   Quote Maureen Quote  Post ReplyReply Direct Link To This Post Topic: Validation script?
    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
Back to Top
morrison View Drop Down
New Member
New Member

Joined: 26 Jan 2015
Points: 32
Post Options Post Options   Quote morrison Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member

Joined: 15 Jul 2011
Location: USA
Points: 4111
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post 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.

Edited by gkaiseril - 13 Oct 2015 at 5:36pm
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

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

This page was generated in 0.047 seconds.