Custom Validation Script with Pop-up Help

Feb 24, 2020

Copy link to clipboard

Copied

Hello there,

I am trying to create a pop up warning based on a validation calculation for a field. 

I have this so far: 

 

If(event.value(Hotel > (Lodging*nDays))) app.alert(“Amount exceeds the lodging per diem limit. Please select a justification for the higher lodging amount.”);

 

I'm getting a Syntax Error saying that I'm missing a before statement and I'm not sure how to move past this. I'm not a JavaScript person so I don't even know where to begin fixing this. Please help!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Use this:

 

if (event.value>(v1*v2)) {
app.alert("Amount exceeds the lodging per diem limit. Please select a justification for the higher lodging amount.");
this.getField("LodgingExceptionDropdown").required = true;
} else {
this.getField("LodgingExceptionDropdown").required = false;
}

TOPICS
Acrobat SDK and JavaScript, Create PDFs, PDF forms

Views

184

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

Custom Validation Script with Pop-up Help

Feb 24, 2020

Copy link to clipboard

Copied

Hello there,

I am trying to create a pop up warning based on a validation calculation for a field. 

I have this so far: 

 

If(event.value(Hotel > (Lodging*nDays))) app.alert(“Amount exceeds the lodging per diem limit. Please select a justification for the higher lodging amount.”);

 

I'm getting a Syntax Error saying that I'm missing a before statement and I'm not sure how to move past this. I'm not a JavaScript person so I don't even know where to begin fixing this. Please help!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Use this:

 

if (event.value>(v1*v2)) {
app.alert("Amount exceeds the lodging per diem limit. Please select a justification for the higher lodging amount.");
this.getField("LodgingExceptionDropdown").required = true;
} else {
this.getField("LodgingExceptionDropdown").required = false;
}

TOPICS
Acrobat SDK and JavaScript, Create PDFs, PDF forms

Views

185

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
Feb 24, 2020 0
Most Valuable Participant ,
Feb 24, 2020

Copy link to clipboard

Copied

Please explain what the validation should be first.

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
Reply
Loading...
Feb 24, 2020 0
Feb 24, 2020

Copy link to clipboard

Copied

Oh, sorry about that. I tried to write it into the code up above (in the IF statement).

 

I want the Hotel field to validate against a calculated value that draws from two other fields. The value I am looking for it to validate against is [Lodging] multiplied byt [nDays]. If the amount entered into the Hotel field is greater than the value of  "Lodging*nDays" then I want the pop up to appear. 

 

Hopefully I'm using the right wording.

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
Reply
Loading...
Feb 24, 2020 0
Most Valuable Participant ,
Feb 24, 2020

Copy link to clipboard

Copied

Do you also want to reject the value entered into the Hotel field in that scenario?

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
Reply
Loading...
Feb 24, 2020 0
Feb 24, 2020

Copy link to clipboard

Copied

No. I do not want to reject the field. I would love to make another field (LodgingExceptionDropdown) required if possible but I didn't want to pile too much onto my question. 

 

Thank you in advance try67!

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
Reply
Loading...
Feb 24, 2020 0
Most Valuable Participant ,
Feb 24, 2020

Copy link to clipboard

Copied

The basic code is this:

 

var v1 = Number(this.getField("Lodging").valueAsString);
var v2 = Number(this.getField("nDays").valueAsString);
if (event.value>(v1*v2)) {
	app.alert("Amount exceeds the lodging per diem limit. Please select a justification for the higher lodging amount.");
}

 

Do you mean that if the alert is shown another field should be made required (and otherwide not)?

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
Reply
Loading...
Feb 24, 2020 0
Feb 24, 2020

Copy link to clipboard

Copied

Yes, that is what I mean. If the alert is shown, another field should be made required.

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
Reply
Loading...
Feb 24, 2020 0
Most Valuable Participant ,
Feb 24, 2020

Copy link to clipboard

Copied

Use this:

 

if (event.value>(v1*v2)) {
app.alert("Amount exceeds the lodging per diem limit. Please select a justification for the higher lodging amount.");
this.getField("LodgingExceptionDropdown").required = true;
} else {
this.getField("LodgingExceptionDropdown").required = false;
}

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
Reply
Loading...
Feb 24, 2020 0
Feb 24, 2020

Copy link to clipboard

Copied

Thank you! This worked perfectly! I always understand the code once I read it/see it but putting it together is not my strong point. 

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
Reply
Loading...
Feb 24, 2020 0