Skip to main content
ryan4mathis
Participant
April 18, 2016
Answered

Verification (app.alert) for read only and submit or nevermind

  • April 18, 2016
  • 2 replies
  • 447 views

Hi javascripting ninjas. I have a MouseUp action on a button titled "Finalize&Email." Based on end user input, it is necessary to add an alert message to curtail a large volume of phone calls "I can't add information into the form anymore."

My intent was to have a button that would make the form "read only" and then submit by attaching the form to an email. But, it now seems that I need an app.alert to go along with it. So, I have been struggling on where to add the "else" statement in the JS below. Without that else statement what I get is - an email attachment with a read only form or an email that is not. What I want is - if the end user chooses "no" the user returns to the form to continue adding information. I am certain this is an easy fix, but I've gone down too many wrong rabbit holes today. Thank you in advance.

var r = app.alert("Are you sure you want to finalize and submit this document? This action cannot be undone.",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

}

}

// This is the form return email. It's hardcoded

// so that the form is always returned to the same address.

// Change address on your form to match the code below

var cToAddr = "CEQA@wildlife.ca.gov"

var cCCAddr = this.getField("PROJECT APPLICANT EMAIL").value + ";" + this.getField("LEAD AGENCY EMAIL").value;

var mySubject=this.getField("Agency").value+"|"+ this.getField("Today").value+"|"+  this.getField("Counter").value+"|"+ this.getField ("Project Title").value;

// Set the body text for the email message

var cBody = "Thank you for submitting your Document.\n\n" + "Save  the filled form attachment for your records\n\n" + "Your document is  now in good hands"

// Send the entire PDF as a file attachment on an email

this.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr, cSubject: mySubject, cMsg: cBody});

This topic has been closed for replies.
Correct answer try67

All you have to do is put the entire code inside the block that starts with the if-condition, like this:

if (r == 4) {

// put code to set fields as read-only and to submit the file here

}

2 replies

ryan4mathis
Participant
April 19, 2016

try67​ thank you so much! That did the trick. Thank you for helping me fix this, and now I can breathe...

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 19, 2016

All you have to do is put the entire code inside the block that starts with the if-condition, like this:

if (r == 4) {

// put code to set fields as read-only and to submit the file here

}