Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Custom Validation Script To Set Drop-down Items

Community Expert ,
Sep 12, 2016 Sep 12, 2016

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.

TOPICS
Acrobat SDK and JavaScript
937
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2016 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2016 Sep 12, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2016 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2016 Sep 12, 2016

I agree, that's the only way you can do it. It's a bit more programming effort, but you do it once, and then use it whenever you need it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2016 Sep 12, 2016
LATEST

Thank you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2016 Sep 12, 2016

Thank you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2016 Sep 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 

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