Radio button reveals required text fields, Submit form button works when those fileds are empty
Hi all. I'll try to keep it as short as possible.
Part1
Have a form, where Submit button executes JS for two things:
1. ensuring one required CB is ticked before submitting
2. extracting email(s) associated to CBs, where each CB export value is an email address, and all CBs have the same name
Submit button >Mouse Up event > Run JS
var fields2 = ["Check Box1.0"];
var addresses2 = [];
for (var i in fields2) {
var v = this.getField(fields2).valueAsString;
if (v!="Off") addresses2.push(v);
}
if (addresses2.length<1) app.alert("Select one Check Box.",1);
else{
var fields = ["email1", " email2", " email3", " email4", " email5", " email6", " email7"];
var addresses = [];
for (var i in fields) {
var v = this.getField(fields).valueAsString;
if (v!="Off") addresses.push(v);
}
if (addresses.length>=1) this.mailDoc({cTo: addresses.join(";"), cSubject: "Subject line goes here"});
else app.alert("Select one email.",1);
}
Works fine.
Part2
Form has 6 required text fields. For this part I created calculation script in hidden Text field, to set a Submit button visible only when all of these 6 fields have values.
var bReady = true;
if(this.getField("Text1").value.length == 0) bReady = false;
else if(this.getField("Text2").value.length == 0) bReady = false;
else if(this.getField("Text3").value.length == 0) bReady = false;
else if(this.getField("Text4").value.length == 0) bReady = false;
else if(this.getField("Text5").value.length == 0) bReady = false;
else if(this.getField("Text6").value.length == 0) bReady = false;
if(bReady) this.getField("Submit").display = display.visible;
else this.getField("Submit").display = display.hidden;
This work fine as well.
Part3
Now, I also created 3 radio buttons, because there is a need for different required text fields to reveal (unhide), depending on which radio button is selected. For example, 1st radio button is set to unhide text fields "Text7" and "Date", as well as "Digital Signature" field (all are required fields when visible). And 2nd radio button is set to unhide text fields "Text8" and "Date" (same date from 1st button), and also "Digital Signature" (same signature from 1st button) field (again all are required fields when visible). 3rd radio button resets form back to default (hides all text fields: "Text7", "Text8", "Digital Signature", "Date").
Something like this for 1st radio button.
Text39,40,41,42 are set to read only, no fill color, and overlaying Text7,8, Digital Sign and Date
app.alert("You must complete required fileds in order to submit.",1);
var oChkFld = this.getField("Group1");
this.getField("Text39").display = oChkFld.value=="Off" ? display.visible : display.hidden;
this.getField("Text7").display = oChkFld.value=="Off" ? display.hidden : display.visible;
this.getField("Text7").required = event.target.value!="Off";
this.getField("Text41").display = oChkFld.value=="Off" ? display.visible : display.hidden;
this.getField("Digital Signature").display = oChkFld.value=="Off" ? display.hidden : display.visible;
this.getField("Digital Signature").required = true ;
this.getField("Text42").display = oChkFld.value=="Off" ? display.visible : display.hidden;
this.getField("Date").display = oChkFld.value=="Off" ? display.hidden : display.visible;
this.getField("Date").required = true ;
this.getField("Text40").display = oChkFld.value=="Off" ? display.visible : display.visible;
this.getField("Text8").display = oChkFld.value=="Off" ? display.visible : display.hidden;
Same for 2nd radio button, only switch Text39 with Text40 and vice versa and Text7 with Text8 and vice versa.
3rd radio button has different script.
if (event.target.value != "Off") {
this.getField("Text7").display = display.hidden ;
this.getField("Text8").display = display.hidden ;
this.getField("Digital Signature").display = display.hidden ;
this.getField("Date").display = display.hidden ;
this.getField("Text39").display = display.visible ;
this.getField("Text40").display = display.visible ;
this.getField("Text41").display = display.visible ;
this.getField("Text42").display = display.visible ;
this.getField("Text7").required = false ;
this.getField("Text8").required = false ;
this.getField("Digital Signature").required = false ;
this.getField("Date").required = false ;
}
app.alert("You must complete required fileds in order to submit.",1);
And finally here is my problem. If 1st radio button is selected and fields "Text7", "Date" and "Digital Signature" are visible, I can't get to work that these 3 fields are required, together with everything described in Part 1 & 2, but without "Text8" in order to submit a form. Same for the 2nd radio button "Text8", "Date" and "Digital Signature" are visible, and must be filled in, in order to submit the form, again, with everything described in Part 1 & 2, but without "Text7".
I've searched for this topic here on forum, but none of solution worked. It's possible that I did it all wrong, so any help is more than welcome.
Tnx in advance.
