Copy link to clipboard
Copied
Hopefully this makes sense!
On my sales contract, I have two 'control' buttons. Button 1 checks that all mandatory fields have been completd and if necessary gives an error message listing the fields that still need completing. If all fields are completed, no error message appears when the button is pressed and the salesperson can continue (document does not get submitted anywhere).
Button 2 makes the document read only, apart from a handful of fields and hides some other fields.
Both buttons work fine, BUT because the salesperson can potentially skip/ignore button 1 and just press button 2, I've been asked to do the following but as JS is still very unknown to me, I'm stuck.
Request 1. Document cannot be made read only until all mandatory fields have been completed
I'm thinking that button 2 should be hidden and only appears when all mandatory fields are completed. Open to other suggestions for this.
This is the code currently on button 1 (button 1 is called HIDE.Contrôle).
var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f= this.getField(this.getNthFieldName(i));
if (f.type!="button" && f.required ) {
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.userName);
}
}
if (emptyFields.length>0) {
app.alert("ERREUR. Au moins une de ces informations suivantes est manquante.\nVous devez compléter l’ensemble de ces informations afin de pouvoir soumettre votre dossier\n\n" + emptyFields.join("\n"));
}
else
{ // All is ok, submit the data
console.println("All form data ok");
}
___________________________________________________________________
Request 2. A password to be added to the 'make read only' button so the salesperson has the opportunity to 'make editible' again if they spot a mistake.
This is the code on button 2 (button 2 is called HIDE.Lock doc)
var r = app.alert("Etes-vous certain de convertir votre document en lecture seule?\n\nVous ne pourrez plus annuler cette operation après la conversion.",2,2);
if (r == 4) { // 4 is Yes, 3 is No
for (var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
this.getField(fname).readonly = true; // makes all fields readonly
// Sett all of the OPEN fields to NOT read-only
getField("OPEN").readonly = false;
getField("OPEN").display = display.visible;
getField("HIDE").display = display.hidden;
}
}
Thank you in advance
Copy link to clipboard
Copied
Bonjour
1.
Il faut modifier votre script ainsi :
var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f= this.getField(this.getNthFieldName(i));
if (f.type!="button" && f.required ) {
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.userName);
}
}
if (emptyFields.length>0) {
app.alert("ERREUR. Au moins une de ces informations suivantes est manquante.\nVous devez compléter l’ensemble de ces informations afin de pouvoir soumettre votre dossier\n\n" + emptyFields.join("\n"));
}
else
{ // All is ok, submit the data
console.println("All form data ok");
this.getField("BOUTON2").display = display.visible;
this.getField("HIDE.Controle").display = display.hidden;
}
2. C'est possible, mais au lieu d'un mot de passe il serait peut-être plus convivial d'utiliser une astuce genre MAJ + clic (ou ctrl + clic) sur le champ concerné ?
3. J'attire votre attention sur le fait qu'il faut absolument éviter les caractères accentués, espaces, etc. dans les noms des champs de formulaire (HIDE.Controle).
Et que ces mêmes caractères doivent être encodés en Unicode dans les messages d'alerte pour s'afficher de façon cohérente en tout cas.
Voir : https://www.abracadabrapdf.net/?p=4736
😉
Copy link to clipboard
Copied
Thanks for the info on not using accented characters.
Point 1 is now working well and button 2 only appears when all mandatory fields are complete.
Could you provide more information on your suggestion for point 2 please:
2. C'est possible, mais au lieu d'un mot de passe il serait peut-être plus convivial d'utiliser une astuce genre MAJ + clic (ou ctrl + clic) sur le champ concerné ?
Thank you