Code for 1. make doc read only ONLY if mandatory fields are done & 2. add password to R/O button
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
