Highlighted

Dropdown list selection question

Community Beginner ,
Nov 18, 2020

Copy link to clipboard

Copied

Hello,

 

I have a dropdown list with values

-- (first value)

01 (second value)

02 

03

 

And a textfield. This text field will have a string - 01 for example.

I want the user to not be able to select the value which is in the textfield, from the dropdown list. I've tried this code but it's not working as expected -I have to click multiple times there to work-- added it in the Mouse Down event for the dropdown list

 

 

if (this.getField("Dropdown").valueAsString==this.getField("Textfield").value)
{
app.alert("this value can't be selected",1);
this.getField("Dropdown").currentValueIndices=0;
}

 

 

Can you please give me an idea? Thank you.

TOPICS
PDF forms

Views

56

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

Dropdown list selection question

Community Beginner ,
Nov 18, 2020

Copy link to clipboard

Copied

Hello,

 

I have a dropdown list with values

-- (first value)

01 (second value)

02 

03

 

And a textfield. This text field will have a string - 01 for example.

I want the user to not be able to select the value which is in the textfield, from the dropdown list. I've tried this code but it's not working as expected -I have to click multiple times there to work-- added it in the Mouse Down event for the dropdown list

 

 

if (this.getField("Dropdown").valueAsString==this.getField("Textfield").value)
{
app.alert("this value can't be selected",1);
this.getField("Dropdown").currentValueIndices=0;
}

 

 

Can you please give me an idea? Thank you.

TOPICS
PDF forms

Views

57

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
Nov 18, 2020 0
Community Beginner ,
Nov 18, 2020

Copy link to clipboard

Copied

I think the code is ok but I'm not placing it in the right place.

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...
Nov 18, 2020 0
Adobe Community Professional ,
Nov 18, 2020

Copy link to clipboard

Copied

Add this script to the Custom Validation script on the dropdown

 

 

event.rc = event.value != this.getField("TextField").valueAsString;
if(!event.rc)
    app.alert("this value can't be selected",1);

 

 

The validation script is the correct place to "validate" a selection. The "event.rc" property determines whether or not the selected value is accepted. The "validation" event occurs before the selected value is actually committed, so the only way to access the current selection is though the event object. 

 

You can read more about dropdown fields here:

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

 

And validation scripts here:

https://www.pdfscripting.com/public/Form-Data-Validation.cfm

 

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...
Nov 18, 2020 1
oanass LATEST
Community Beginner ,
Nov 18, 2020

Copy link to clipboard

Copied

Thank you very much for the code and for the links!

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...
Nov 18, 2020 0