Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Validation on Submit Causes Scripts to Stop Working

Engaged ,
Aug 05, 2021 Aug 05, 2021

Copy link to clipboard

Copied

I'm having an issue with a validation script I have running on the MouseUp of a submit button using the mailDoc() method.

I have blur scripts on a text field that no longer work if submit button is clicked. I'm not seeing anything in this script that could be causing this. The entire point of validation is to ensure the form is filled out properly and have the user go back to the field(s) that weren't to fix them, so this needs to function properly.

Could it be the setFocus()?

var writer = this.getField("writer").value;
var coachVal = this.getField("coach").value;
var po = this.getField("po").value;
var manufacturer = this.getField("manufacturer").value;
var email = this.getField("email").value;
var warranty = this.getField("warranty").value;
var detVal = this.getField("details").value;
var sVal = service.value;
var tvVal = tvNum.value;
var cBreak = "\n\n";
var ffEmail = "email address";
var spyEmail = "email address";
var nTablet = "email address";
var nSub = "New Service Request Submittal for " + manufacturer + " coach #" + coachVal;
var ffBody = "Name," + cBreak + writer + " has submitted a service request for a " + manufacturer + 
" unit. The coach number is: " + coachVal + ". The service needed is: " + sVal + ". This service is " 
+ warranty + "." + cBreak + "Details:" + cBreak + detVal;
var spyBody = "Name," + cBreak + writer + " has submitted a service request for a " + manufacturer + 
" unit. The coach number is: " + coachVal + ". The service needed is: " + sVal + ". This service is " 
+ warranty + "." + cBreak + "Details:" + cBreak + detVal;
var FF = ffEmail + nSub + ffBody;
var SPY = spyEmail + nTablet + nSub + spyBody;
//check for required fields and ensure they are filled out
var requiredFields = new Array();
for (var i = 0; i < this.numFields; i++) {
var fName = this.getNthFieldName(i);
var f = this.getField(fName);
if (f.type!="button" && this.getField(fName).required && (this.getField(fName).value == "")) {
requiredFields[requiredFields.length] = fName;
}
}
var error = "Please complete the following fields: \n\n";
for (j=0; j < requiredFields.length; j++) {
if (requiredFields[j].value == null) {
error = error + requiredFields[j] + "\n";
var f2 = this.getField(requiredFields[j]);
f2.setFocus();
}
}
//produce required fields error or submit if no error
if (requiredFields.length > 0) {
app.alert({cMsg: error, nIcon: 1, cTitle: "Required Field(s) Error"});
}
else {
if(vendor.value == "Name") {
date.value = util.printd("mm/dd/yyyy", new Date());
request.value = util.printd("hh:MM tt", new Date());
this.mailDoc({cTo: ffEmail, cSubject: nSub, cMsg: ffBody, cSubmitAs: "PDF"});
}
else if(vendor.value == "Name") {
date.value = util.printd("mm/dd/yyyy", new Date());
request.value = util.printd("hh:MM tt", new Date());	
this.mailDoc({cTo: spyEmail, cCC: nTablet, cSubject: nSub, cMsg: spyBody, cSubmitAs: "PDF"});
}
else {
app.alert({cMsg: "Please Select the appropriate vendor for your coach. Vendor selection is located above the Issues field.", nIcon: 1, cTitle: "Vendor Not Selected"});
}
}

 

TOPICS
Create PDFs, JavaScript, PDF forms

Views

18

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

correct answers 1 Correct answer

Engaged , Aug 05, 2021 Aug 05, 2021
The submit button script had a variable of the multiline field's value named as the same variable that I named the field with. This was causing the issue.Document Level:var details  =  this.getField("details");Submit Button:var details  =  this.getField("details").value;

Likes

Translate

Translate
Engaged ,
Aug 05, 2021 Aug 05, 2021

Copy link to clipboard

Copied

I was just working with the code more and completely removed the field validation, and it's still causing the blur event scripts to not function.

Here are the scripts on the blur event:

//blur event field 1
var y = this.getField("box.num").value;
function lsString(num) {
	var rSTR = "";
	var i = 1;
	while (num > 0) {
		if(service.value == "Add/Change Light Circuit(s)") {
			var	cLight = "Light " + i + ": \nName: xxx\nPhysical Location: xxx\nCircuit Number: xxx\n\n";
			rSTR += cLight;
		}
		else if(service.value == "Add/Change Shade Circuit(s)") {
			var	cShade = "Shade " + i + ": \nName: xxx\nPhysical Location: xxx\nCircuit Number: xxx\n\n";
			rSTR += cShade;
		}
		num--;
		i++;
	}
	return rSTR;
}
if(service.value == "Add/Change Light Circuit(s)" || service.value == "Add/Change Shade Circuit(s)") {
	details.value = lsString(y) + "\n";
	if(!event.value) {
		details.value = details.value;
		this.getField("info").value = "";
	}
	else {
		this.getField("info").value = "Changing the number of circuits after manually entering text in the details box will delete all manual text entries. Ensure there aren't changes to be made prior to editing.";
	}
}
//blur event field 2
var x = this.getField("tvs.num").value;
function tvString(num) {
	var rSTR = "";
	var i = 1;
	while (num > 0) {
		if(service.value == "Apple TV(s)") {
			var	tvApple = "Apple TV " + i + ": \nModel: xxx\nPhysical Location: xxx\nDevice Plugged Into: xxx\nHDMI Input: xxx\n\n";
			rSTR += tvApple;
		}
		else if(service.value == "DirecTV to Dish") {
			var	tvSat = "Satellite " + i + ": \nModel: xxx\nPhysical Location: xxx\nDevice Plugged Into: xxx\nHDMI Input: xxx\n\n";
			rSTR += tvSat;
		}
		num--;
		i++;
	}
	return rSTR;
}
if(service.value == "Apple TV(s)" || service.value == "DirecTV to Dish") {
	details.value = tvString(x) + "\n";
	if(!event.value) {
		details.value = details.value;
		this.getField("info").value = "";
	}
	else {
		this.getField("info").value = "Changing the number of TVs after manually entering text in the details box will delete all manual text entries. Ensure there aren't changes to be made prior to editing.";
	}
}

 

I'm also trying to get a validation to work based on the contents of a multiline text field. The above code adds strings to the field that include "xxx". We want the user to change "xxx" to the proper information by creating an app alert that targets any use of "xxx" using the indexOf() method.

var z = event.value.indexOf("xxx");
if(event.value == z) {
app.alert("Missing information. Please replace any \"xxx\" text with the information it pertains to.");
event.rc = false;
}
else {
event.rc = true;
}

 

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
Engaged ,
Aug 05, 2021 Aug 05, 2021

Copy link to clipboard

Copied

LATEST

The submit button script had a variable of the multiline field's value named as the same variable that I named the field with.

 

This was causing the issue.

Document Level:

var details  =  this.getField("details");

Submit Button:

var details  =  this.getField("details").value;

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