abracadabraPDF › Forums › PDF – Général › Raz et remplissage automatique › Répondre à : Raz et remplissage automatique
Autre chose, j’ai lu ton code de reset qui mouline beaucoup et inutilement :
- il faut oublier le “f” !
- “100” c’était un exemple, dans un premier temps tu pourrais utiliser un chiffre plus modeste.
S’agissant d’une propriété partagée (display, color, etc) quand on s’adresse à un champ parent on s’adresse à tous ses enfants.
Par exemple :
this.getField("Q.1).display = display.hidden;
suffit à masquer tous les champs dont le nom commence par “Q.1.”
Donc la première partie de la fonction Raz() :
function Raz() {
this.getField("Erreurs").value = 0;
this.getField("Menu.5").value = 0;
for (var i = 1 ; i<101 ; i++) {
for (var f = 0 ; f<101 ; f++) {
if (this.getField("Q."+i +"."+f) != null) {this.getField("Q."+i +"."+f).display = display.hidden;
this.getField("Q."+i +"."+f).fillColor=color.white;
}
if (this.getField("TQ."+i +"."+f) != null) {this.getField("TQ."+i +"."+f).display = display.hidden;}
if (this.getField("Question."+i +"."+f) != null) {this.getField("Question."+i +"."+f).display = display.hidden;}
if (this.getField("Verifier."+i +"."+f) != null) {this.getField("Verifier."+i +"."+f).display = display.hidden;}
if (this.getField("Recommencer."+i +"."+f) != null) {this.getField("Recommencer."+i +"."+f).display = display.hidden;}
if (this.getField("Aide."+i +"."+f) != null) {this.getField("Aide."+i +"."+f).display = display.hidden;}
}
}
...
Pourrait être simplifiée ainsi (sans les 100 x 100 boucles “f”) :
function Raz() {
this.getField("Erreurs").value = 0;
this.getField("Menu.5").value = 0;
for (var i = 1 ; i<101 ; i++) {
if (this.getField("Q."+i) != null) {
this.getField("Q."+i).display = display.hidden;
this.getField("Q."+i).fillColor=color.white;
}
if (this.getField("TQ."+i) != null) {this.getField("TQ."+i).display = display.hidden;}
if (this.getField("Question."+i) != null) {this.getField("Question."+i).display = display.hidden;}
if (this.getField("Verifier."+i) != null) {this.getField("Verifier."+i).display = display.hidden;}
if (this.getField("Recommencer."+i) != null) {this.getField("Recommencer."+i).display = display.hidden;}
if (this.getField("Aide."+i) != null) {this.getField("Aide."+i).display = display.hidden;}
}
…