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;
}
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;
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
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.
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)?
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:
- this.getField("field5").display = (this.getField("field1").value == "a") &&
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;
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?
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?
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?
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