Multiple Checkboxes - AT LEAST one required

New Here ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

I have a form that has several radio button and checkboxes.  I do not want the form to be submitted until all the required fields and at least one checkbox are checked.  Once complete, the form will be emailed to me.

 

The required fields work like a charm.  However, I can't seem to get the checkboxes to do the same....checked or unchecked, the form still attempts to email me (see example).  

 

I've read several older posts that were shared but I'm missing something.  Any advice would be greatly appreciated. 

 

Below is the script:

 

var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f!=null && f.type!="button" && f.required && f.valueAsString==f.defaultValue) {
emptyFields.push(f.name);
}
}
if (emptyFields.length>0) {

app.alert("You must fill in the following fields:\n" + emptyFields.join("\n"));

} else this.mailDoc({cTo: "diane.hands@wellstone.com",cSubject: "Staff Enrollment Form"});

 

 

 

 

 

TOPICS
Acrobat SDK and JavaScript , Windows

Views

56

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

It has to be done separately. What are the names of those check-boxes?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

The boxes are named "Check Box21.0.0 through Check Box21.0.16". 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

LATEST

Before this line:

 

if (emptyFields.length>0) {

 

Add this:

 

var isBoxChecked = false;
for (var i=0; i<=16; i++) {
	if (this.getField("Check Box21.0."+i).valueAsString!="Off") isBoxChecked = true;
}
if (isBoxChecked==false) emptyFields.push("At least one box from Check Box21.0.1 - Check Box21.0.16");

 

You can adjust the description of the check-boxes group (the text in the last line) to something more meaningful, of course.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines