Skip to main content
Participating Frequently
March 8, 2018
Question

If condition of several fields is met then show image (on spawned page)

  • March 8, 2018
  • 1 reply
  • 1240 views

I have the following scenario:

First page ist standard

second page is being spawned out of an template

field1(text) is on the first page

field2 (text), field3 (numbers), field4 (numbers), field5 (image) are on the spawned page

if field1 is "a" && 

field2 is "b"  &&

field3 is "1"  &&

field4 is "2"

then field5 is visible

the normal state of field5 is set invisible

how can I manage this, and where does the code go?

does the code go to one of the text or the number fields or to the image field (there are about 40 image fields which visibility would be controlled over that script)

based on some code that Karl Heinz Kremer​ gave me to work with spawned pages I have managed to make it work just with two fields (script running as validation in field1)

// get this fields name

var fieldName = event.target.name;

// strip off the last part of the name

var groupName = fieldName.substring(0, fieldName.lastIndexOf(".")+1);

if (event.value == "a")

{

this.getField(groupName + "field5").display = display.visible;

}

This topic has been closed for replies.

1 reply

Karl Heinz  Kremer
Community Expert
Community Expert
March 8, 2018

You want to change the field's "display" property. See here for information about this property in the Javascript API: Acrobat DC SDK Documentation

Once you know how "display" works, try this code as part of the "field5" calculation script:

// get this fields name

var fieldName = event.target.name;

// strip off the last part of the name

var groupName = fieldName.substring(0, fieldName.lastIndexOf(".")+1);

// calculate the display property of this field

event.target.display = (this.getField("field1").value  == "a") &&

    (this.getField(groupName + "field2").value == "b") &&

    (this.getField(groupName + "field3").value == 1) &&

    (this.getField(groupName + "field4").value == 2) ? display.visible : display.hidden;

frejmAuthor
Participating Frequently
March 8, 2018

Thanks fro taking the time to reply Karl Heinz!

I checked the "display" property, thanks for pointing that out!

Thanks for providing the code.

What I don't understand is where would field5 (the image field) go in the code?

my scenario would be:

if field1 = a &&

if field2 = b &&

if field3 = 1 &&

if field4 = 2 &&

then field5 would be display.visible

I have 40 image fields that would be shown if different conditions are met by the other fields like:

if field1 = b &&

if field2 = c &&

if field3 = 2 &&

if field4 = 3 &&

then field6 would be display.visible

where would I put the code? in any validation field of field1-4? thanks a lot in advance

Karl Heinz  Kremer
Community Expert
Community Expert
March 8, 2018

Sorry, forgot to mention that: It would be the calculation script of field5. You don't want to use it as a validation script in any of the four fields you need to check, because such a validation script would only be executed when the value of the associated field changes. You could of course add it to all four fields, but having it in just the target field cuts down on the amount of code you have to produce.