Copy link to clipboard
Copied
I have two dropdown fields "BusServiceType" and "D1Period1" in an Acrobat DC form.
I am trying to write a validation script to check "D1Period1" when "BusServiceType" equals a certain value.
The script is added to the Custom Keystroke Script property of both fields.
A simple "app.alert()" test works, proving JS can run.
But change detection scripts on the field value itself do not function.
Here is pseudocode for what I have tried:
Copy code
Steps taken:
No errors show in console. The script just seems to not run on value change.
Any ideas what could cause this or how I can troubleshoot further? Is there a limitation in Acrobat around custom field scripting?
Please let me know if submitting this on the forums could help escalate to Adobe! I'm happy to provide any other details.
Let me know if you need any changes or have additional details to include. Providing code samples and debugging steps done will help them diagnose potential causes.
Copy link to clipboard
Copied
Use the validation property of the fields.
Copy link to clipboard
Copied
I am trying to validate the selections in two dropdown fields, "BusServiceType" and "D1Period1" in an Acrobat DC form I created.
My goal is to show an error message if "D1Period1" does not equal a certain value when "BusServiceType" is set to "Night Bus Service".
I added the following JavaScript code to the Custom Keystroke Script properties of both fields:
if(this.value === "Night Bus Service" && this.getField("D1Period1").value !== "Night Time") { app.alert("Please select Night Time"); }
I have also tried various simplified versions:
app.alert("Test");
But the change validation code does not ever run when selecting values in the fields.
The test alert works fine, so JavaScript in general is enabled and working.
What could cause the field value validation code to not function?
Is there something special needed to detect form field changes via JavaScript in Acrobat DC?
I have tried across multiple documents and reader/editor users. Permissions set properly.
Please advise how to properly create dropdown value validation scripts.
[moderator: merged this thread with similar thread from the same user]
Copy link to clipboard
Copied
Your script is close, try this:
if(this.getField("BusServiceType").valueAsString === "Night Bus Service" && event.value !== "Night Time") {
app.alert("Please select Night Time"); }
Use script in 'Validate' tab.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now