Skip to main content
PDF Automation Station
Community Expert
Community Expert
September 12, 2016
Question

Custom Validation Script To Set Drop-down Items

  • September 12, 2016
  • 2 replies
  • 1020 views

I am trying to use a custom validation script (or a custom keystroke script - whatever is best) in a drop-down to set the items in another drop-down based on the display value (not the export value).  If I use the export value, it works without issue.  If I use the display value, it is always one step behind the selection.  I am using the following validation script in Dropdown1:

if(event.target.getItemAt(event.target.currentValueIndices, false)=="A")

{

this.getField("Dropdown2").setItems(["aa","aaa"])

}

if(event.target.getItemAt(event.target.currentValueIndices, false)=="B")

{

this.getField("Dropdown2").setItems(["bb","bbb"])

}

When I select "A" in dropdown one, it sets the items as if I selected "B" and vice versa.

This topic has been closed for replies.

2 replies

Karl Heinz  Kremer
Community Expert
Community Expert
September 12, 2016

When the custom keystroke event handler gets executed, the target field has not yet been updated. That's why you are getting the previous value. You need to access the modified value via event.value: Acrobat DC SDK Documentation - event.value 

try67
Community Expert
Community Expert
September 12, 2016

In the Validation event the new value has not been committed to the field yet (it's still being validated, after all), so accessing the field's value property will return the old value, not the new one. To access the new value you should use event.value.

PDF Automation Station
Community Expert
Community Expert
September 12, 2016

event.value works but it pulls the export value.  I need the display value.  Is there a way to do this?

try67
Community Expert
Community Expert
September 12, 2016

It's tricky. The only way I found is to loop over all the items (using numItems and getItemAt), comparing them to the selected value, and then getting the display value by using getItemAt, but this time with the bExportValue parameter set to false.