• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Custom Validation Script with Pop-up Help

New Here ,
Feb 24, 2020 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!

TOPICS
Acrobat SDK and JavaScript

Views

658

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 2 Correct answers

Community Expert , Feb 24, 2020 Feb 24, 2020

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)?

Votes

Translate

Translate
Community Expert , Feb 24, 2020 Feb 24, 2020

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;
}

Votes

Translate

Translate
Community Expert ,
Feb 24, 2020 Feb 24, 2020

Copy link to clipboard

Copied

Please explain what the validation should be first.

Votes

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
New Here ,
Feb 24, 2020 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.

Votes

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
Community Expert ,
Feb 24, 2020 Feb 24, 2020

Copy link to clipboard

Copied

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

Votes

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
New Here ,
Feb 24, 2020 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!

Votes

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
Community Expert ,
Feb 24, 2020 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)?

Votes

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
New Here ,
Feb 24, 2020 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.

Votes

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
Community Expert ,
Feb 24, 2020 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;
}

Votes

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
New Here ,
Feb 24, 2020 Feb 24, 2020

Copy link to clipboard

Copied

LATEST

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. 

Votes

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