Skip to main content
Participant
August 16, 2023
Question

App alert upon submission listing empty fields but with exceptions for specific sets of checkboxes

  • August 16, 2023
  • 1 reply
  • 919 views

Hi guys, help. I've been working on a long questionnaire whereupon clicking the submit button at the end, I would like an app alert to list all empty fields, including checkboxes. But with an exception: if those under a set of multi-option checkboxes has at least one box checked, then exclude these from being listed in the app alert. BUT if no boxes in the set is checked, then include them in the alert. Example, I have 2 sets of checkboxes: first set is named cbA with boxes cbA1, cbA2, cbA3. This group has at least one box checked making this set valid, thus all cbA checkboxes should be excluded from the alert. Set2 is named cbB with boxes cbB1, cbB2, cbB3 and not one of its boxes are checked which isn’t valid, so include all cbB checkboxes in the alert list of empty fields. Any help would be much appreciated.

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
August 16, 2023

Exactly what text do you want listed?  The field names are not likely to make any sense to the user. The best option is to use the tooltip text, which means you'll need to make sure its set for all fields. 

Listing all radio buttons in a group is another issue. The tooltip text is the same for all buttons since they are all the same field. The only text that differentiates them is the export value. 

 

Here's how it's done. Loop over all the fields in the form, testing the current value against the default value. Buttons will need to be excluded.

 

 

var oFld, aEmptyList = [];
for(var i=0;i<this.numFields;i++)
{
   oFld = this.getField(this.getNthFieldName(i));
   if(oFld.type != "button")
   {
      if(oFld.value == oFld.defaultValue)
      {
         aEmptyList.push(oFld.userName);
      }
   }
}
if(aEmptyList.length)
   app.alert("Missing Fields:\n" + aEmptyList.join(", "),1,0);

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
August 17, 2023

Sorry it's still me just a diff account due to org restrictions. Thanks for the prompt reply, I copied the exact same script and works for all other fields except the multi-option checkboxes. I attached the sample form, grateful if you could check. I'm thinking it has something to do with differing box names under a multi-option format, unlike for single option that requires a single name for all boxes. Not sure how to go about it.

Thom Parker
Community Expert
Community Expert
August 17, 2023

The code works exactly as described. I noted in the previous answer that radio/check groups all have the same tooltip. So you'll need to specify how you want these handled. 

You also must be more explicit about what you think is working and what is not. The Yes/No checkboxes are setup correctly as a button group. But the Q3 and Q4 checks are not setup as a mutually exclusive buttn group.    So they respond differently to the code. Be specific. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often