Skip to main content
sams87040792
Participant
October 29, 2018
Answered

How to check if all required fields have been filled in before submitting a document as read only?

  • October 29, 2018
  • 1 reply
  • 8639 views

Hello,

I am making a form with required fields. I would like the form to do the following when the submit button is pushed:

1: check to make sure all required fields are filled out.

  •      if all fields are filled in then, form converts to read only
  •      if not all fields are fill in then, user is notified that not all fields are filled in

2:  Once form is read only, send email with subject as one of the fields

I have been researching this for weeks and have been trying lots of options, but haven't found one that works. Any help is appreciated! Thanks!

This topic has been closed for replies.
Correct answer try67

You can use this code to achieve it:

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 {

    for (var i=0; i<this.numFields; i++) {

        var f = this.getField(this.getNthFieldName(i));

        if (f!=null) f.readonly = true;

    }

    var subjectLine = this.getField("Text1").valueAsString;

    var msgBody = "This is the message body of the email";

    this.mailDoc({cTo: "me@server.com", cSubject: subjectLine, cMsg: msgBody});

}

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
October 29, 2018

You can use this code to achieve it:

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 {

    for (var i=0; i<this.numFields; i++) {

        var f = this.getField(this.getNthFieldName(i));

        if (f!=null) f.readonly = true;

    }

    var subjectLine = this.getField("Text1").valueAsString;

    var msgBody = "This is the message body of the email";

    this.mailDoc({cTo: "me@server.com", cSubject: subjectLine, cMsg: msgBody});

}

sams87040792
Participant
October 29, 2018

Thanks so much! This worked perfectly!

Participant
August 26, 2023

In what way