Highlighted

Drop Down SetItems() resets the list

New Here ,
Oct 13, 2020

Copy link to clipboard

Copied

Hi, everyone. I have a script in drop down field named "MODEL". It has two options is the list, G2500 and ONYX. Depending the selection, the script changes/sets the items of the list. When I try to select an item from the drop down list G1CDU other than first item, it goes back to the first item. So, I'm not able to select any other item.

this.getField("G1CDU").clearItems();
switch (event.value) {
case "G2500":
this.getField("G1CDU").setItems([
"Item 1",
"Item 2",
"Item 3"]);
break;

case "ONYX":
this.getField("G1CDU").setItems([
"Item 4",
"Item 5",
"Item 6"]);
break;

}

 Can you please help me in this regard?

Try using this code as custom validation script of MODEL field:

var seti = this.getField("G1CDU");

if (event.value == "G2500") {
seti.clearItems();
seti.insertItemAt("Item3");
seti.insertItemAt("Item2");
seti.insertItemAt("Item1");
} else if ( event.value == "ONYX"){
seti.clearItems();
seti.insertItemAt("Item6");
seti.insertItemAt("Item5");
seti.insertItemAt("Item4");
}

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

32

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

Drop Down SetItems() resets the list

New Here ,
Oct 13, 2020

Copy link to clipboard

Copied

Hi, everyone. I have a script in drop down field named "MODEL". It has two options is the list, G2500 and ONYX. Depending the selection, the script changes/sets the items of the list. When I try to select an item from the drop down list G1CDU other than first item, it goes back to the first item. So, I'm not able to select any other item.

this.getField("G1CDU").clearItems();
switch (event.value) {
case "G2500":
this.getField("G1CDU").setItems([
"Item 1",
"Item 2",
"Item 3"]);
break;

case "ONYX":
this.getField("G1CDU").setItems([
"Item 4",
"Item 5",
"Item 6"]);
break;

}

 Can you please help me in this regard?

Try using this code as custom validation script of MODEL field:

var seti = this.getField("G1CDU");

if (event.value == "G2500") {
seti.clearItems();
seti.insertItemAt("Item3");
seti.insertItemAt("Item2");
seti.insertItemAt("Item1");
} else if ( event.value == "ONYX"){
seti.clearItems();
seti.insertItemAt("Item6");
seti.insertItemAt("Item5");
seti.insertItemAt("Item4");
}

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

33

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
Oct 13, 2020 0
Engaged ,
Oct 14, 2020

Copy link to clipboard

Copied

Try using this code as custom validation script of MODEL field:

var seti = this.getField("G1CDU");

if (event.value == "G2500") {
seti.clearItems();
seti.insertItemAt("Item3");
seti.insertItemAt("Item2");
seti.insertItemAt("Item1");
} else if ( event.value == "ONYX"){
seti.clearItems();
seti.insertItemAt("Item6");
seti.insertItemAt("Item5");
seti.insertItemAt("Item4");
}

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...
Oct 14, 2020 0
New Here ,
Oct 14, 2020

Copy link to clipboard

Copied

Thank you for your help. I tried the if statement like yours. I have figured it out.

I was using javascript in custom calculation script. Now, I'm using it in custom validation script and it is working fine.

Thank you.

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...
Oct 14, 2020 0