Skip to main content
JR Boulay
Community Expert
Community Expert
October 1, 2019
Frage

My JavaScript run twice instead of once

  • October 1, 2019
  • 3 Antworten
  • 1155 Ansichten

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);
}
}
}
}

Dieses Thema wurde für Antworten geschlossen.

3 Antworten

Inspiring
October 2, 2019

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.

JR Boulay
Community Expert
Community Expert
October 1, 2019

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...

Acrobate du PDF, InDesigner et Photoshopographe
Legend
October 1, 2019

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.