My JavaScript run twice instead of once

Adobe Community Professional ,
Oct 01, 2019 Oct 01, 2019

Copy link to clipboard

Copied

I have a problem that drives me crazy.
In my PDF I use a function that fills the right drop-down menu and depends on the choice made in the left drop-down menu.
This function works well except that:

- When I use my function in "validation script" it acts with a delay time, it is the previous choice that is displayed in the right drop-down list. )See attachment).

- When I use my function in "custom format script" it runs twice. ( See attachment.)
• Once when you click on the list, as if there was a "mouse down" action, which immediately resets the right drop-down list.
• And a second time, as expected, when you validate a choice.

 

What do I need to change to be able to use my function as a "validation script" that don't acts with a delay time, or as a "custom format script" that only runs once after the user choice?

Thank you

 

My function:

 

function gereSousList() {

if (event.target.currentValueIndices != 0) {

// console.clear();
// récupération du suffixe du champ cliqué
var aTexte = event.target.name.split(".");
var nSuffix = aTexte.pop();
// console.println("nSuffix : "+nSuffix);

// récupération du numéro de l'item sélectionné
var cPos = event.target.currentValueIndices;
// console.println("cPos : "+cPos);

if (this.dataObjects[cPos] != undefined) {
// importation des données en fonction du numéro de l'item (fichier en PJ)
var p2 = this.getDataObject(this.dataObjects[cPos].name);
if (this.dataObjects != null) {
var fi2 = this.getDataObjectContents(p2.name);
var fit2 = util.stringFromStream(fi2);
// console.println("\n\nNom du fichier source : "+this.dataObjects[cPos].name);

// séparation des rangées
var datarr2 = fit2.split("\n");
// console.println("datarr2 : "+datarr2);

 

// remplissage de la liste déroulante
this.getField("SitProf.liste2." + nSuffix).clearItems();
this.getField("SitProf.liste2." + nSuffix).setItems(datarr2);
}
}
}
}

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

185

Likes

translate

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
community guidelines
Most Valuable Participant ,
Oct 01, 2019 Oct 01, 2019

Copy link to clipboard

Copied

The problem may be doing things in the validation script. They are only for validation, may be called more times than you think, and should not have side effects.  

 

Similarly, the custom format script should only be used for custom formatting, not for side effects.

Likes

translate

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
community guidelines
Adobe Community Professional ,
Oct 01, 2019 Oct 01, 2019

Copy link to clipboard

Copied

When I put my function in a mouse-up action the behavior is the same as with the "validation script": the drop-down list on the right displays what corresponds to the previous selection...

SOS...

Likes

translate

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
community guidelines
Adobe Community Professional ,
Oct 02, 2019 Oct 02, 2019

Copy link to clipboard

Copied

You really should use a custom Keystroke script for this, but you'd have to modify your code. It shouldn't be too difficult to find some samples, but post again if you get stuck.

Likes

translate

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
community guidelines