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

Community Beginner ,
Mar 08, 2018

Copy link to clipboard

Copied

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;

}

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

227

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

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

Community Beginner ,
Mar 08, 2018

Copy link to clipboard

Copied

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;

}

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

228

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 08, 2018 0
Adobe Community Professional ,
Mar 08, 2018

Copy link to clipboard

Copied

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;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 08, 2018 1
Community Beginner ,
Mar 08, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 08, 2018 0
Adobe Community Professional ,
Mar 08, 2018

Copy link to clipboard

Copied

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. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 08, 2018 1
Community Beginner ,
Mar 08, 2018

Copy link to clipboard

Copied

ahh I see that makes sense!

where do I put the code for the image field in the settings of the field (sorry working with the German version)?

Bildschirmfoto 2018-03-08 um 15.11.18.jpg

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 08, 2018 0
Adobe Community Professional ,
Mar 08, 2018

Copy link to clipboard

Copied

In diesem Fall würde ich ein (und jetzt fehlen mir die deutschen Worte, weil ich Acrobat nur in der Englischen Version verwende) "hidden" und "read-only" Textfeld zum Formular hinzufügen, und dann das Script (mit einer kleinen Modifikation) als "Calculation" Script verwenden. Die Zeile #8 im Script muss wie folgt geändert werden:

  1. this.getField("field5").display = (this.getField("field1").value  == "a") &&

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 08, 2018 1
Community Beginner ,
Mar 08, 2018

Copy link to clipboard

Copied

danke für deine Antwort!

leider kein Erfolg funktioniert perfekt!

field5 also das image field habe ich als hidden gesetzt, mit dem script sollte es ja dann visible werden richtig?

hab ein Textfeld erstellt das hidden und readonly ist und den code unten als custom calculation script eingefügt:

// 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

this.getField("field5").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;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 08, 2018 0
Community Beginner ,
Mar 08, 2018

Copy link to clipboard

Copied

leider zu früh gefreut 😞

Auf dem template funktioniert alles perfekt, wenn ich die Seite dann spawne leider nicht.

field2 & field3 & field4 sind dropdown lists, alle in den settings auf "Ausgewählten Wert sofort einsetzen" gesetzt.

field1 ist auf einer statischen seite davor die nicht gespawnt wird, der fieldname ändert sich also nie, sollte ja aber für das script keine rolle spielen.

woran könnte es liegen das das script auf einer gespawnten seite nicht funktioniert?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 08, 2018 0
Community Beginner ,
Mar 09, 2018

Copy link to clipboard

Copied

alles getestet, hab auch mal nur text Felder genommen, aber sobald eine Seite gespawnt wird und der Name der Felder sich zu Pnn.template.field ändert geht nichtsmehr.

Haben Sie vllt einen tip woran es liegen könnte Karl Heinz Kremer​?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 09, 2018 0
Adobe Community Professional ,
Mar 09, 2018

Copy link to clipboard

Copied

Werden Fehler auf der JavaScript Console angezeigt (Ctrl-J oder Cmd-J auf dem Mac)? Wenn ja, was ist die genaue Fehlermeldung?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 09, 2018 0
frejm LATEST
Community Beginner ,
Mar 09, 2018

Copy link to clipboard

Copied

folgende Fehler werden ausgegeben :

TypeError: this.getField(...) is null

10:Field:Calculate

TypeError: this.getField(...) is null

10:Field:Calculate

TypeError: this.getField(...) is null

10:Field:Calculate

TypeError: this.getField(...) is null

10:Field:Calculate

TypeError: this.getField(...) is null

10:Field:Calculate

TypeError: this.getField(...) is null

10:Field:Calculate

TypeError: this.getField(...) is null

10:Field:Calculate

TypeError: this.getField(...) is null

10:Field:Calculate

TypeError: this.getField(...) is null

10:Field:Calculate

TypeError: this.getField(...) is null

10:Field:Calculate

TypeError: this.getField(...) is null

11:Field:Calculate

TypeError: this.getField(...) is null

11:Field:Calculate

NotAllowedError: Sicherheitseinstellungen verhindern den Zugriff auf diese Eigenschaft oder Methode.

Doc.saveAs:1:Field save:Mouse Up

NotAllowedError: Sicherheitseinstellungen verhindern den Zugriff auf diese Eigenschaft oder Methode.

Doc.saveAs:1:Field save:Mouse Up

NotAllowedError: Sicherheitseinstellungen verhindern den Zugriff auf diese Eigenschaft oder Methode.

Doc.saveAs:1:Field save:Mouse Up

TypeError: this.exportAsPDF is not a function

1:Field:Mouse Up

NotAllowedError: Sicherheitseinstellungen verhindern den Zugriff auf diese Eigenschaft oder Methode.

Doc.saveAs:1:Field save:Mouse Up

TypeError: this.getField(...) is null

21:Field:Mouse Up

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 09, 2018 0