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

Create message for required fields

Community Beginner ,
Dec 09, 2019 Dec 09, 2019

Copy link to clipboard

Copied

Hello,

I have several fields on a form that are required. Instead of displaying a generic message stating that a required field has been left blank, I would like to display a specific message for each required field, if left blank. Below if what I was trying to start off with but I get a syntax error stating "missing; Before Statement 1: at line 2

 

Var CoreBankName = this.getField("282_Core_Ref_Bank_Name");
if (CoreBankName !== null)
{
CoreBankName.setFocus()
app.alert("Core Client Bank Name is required")
};

TOPICS
Acrobat SDK and JavaScript

Views

400

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 ,
Dec 09, 2019 Dec 09, 2019

Copy link to clipboard

Copied

NODIFIED REPLIED , I MADE AN ERROR SEE BELOW AGAIN

 

If you copy and pasted your code here, it looks like the problem is because the semicolon is outside the instruction line; it should be inside  of the curley braces.

 

See your line 2 here:

 

if (CoreBankName !== null)
{
CoreBankName.setFocus()
app.alert("Core Client Bank Name is required")
};

 

 

 

Specifically this part of line 2 : 

 

 app.alert("Core Client Bank Name is required")
};

 

 

 

It should read like this:

 

app.alert("Core Client Bank Name is 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 ,
Dec 09, 2019 Dec 09, 2019

Copy link to clipboard

Copied

Your code is not checking if the field's value is empty, but if the field itself exists.

Also, the required property doesn't check if a field is blank, but if it has a value that's not the same as its default value.

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 ,
Dec 09, 2019 Dec 09, 2019

Copy link to clipboard

Copied

Ok I got lost with your reply a little bit.

 

Can you re-explain please what does the "if it's null" is implying in the code above?

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 ,
Dec 09, 2019 Dec 09, 2019

Copy link to clipboard

Copied

If no field exists with the name parameter you pass to getField it will return null. If it does exist it will return a Field object.

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 ,
Dec 09, 2019 Dec 09, 2019

Copy link to clipboard

Copied

Great. Thank you!

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 Beginner ,
Dec 09, 2019 Dec 09, 2019

Copy link to clipboard

Copied

I made the change but still getting the same error. Again, this is a field I have set to be required. I'm trying to check to see if it is null. If it is, then I display a message stating that, that specific field is required. Since I will have about 20 required fields, I want to see if I can get these types of messages more specific to which field needs to be filled in. Below is the code sample where I'm getting the "Syntax Error: missing ; before statement 1: at line 2"

 

Var CoreBankName = this.getField("282_Core_Ref_Bank_Name");
if (CoreBankName !== null)
{    
   CoreBankName.setFocus()    
   app.alert("Core Client Bank Name is 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 ,
Dec 09, 2019 Dec 09, 2019

Copy link to clipboard

Copied

MODIFIED ANSWER

 

I apologize, I am also learning javascripting but I am going to try again.

 

You also have Var  spelled with the first letter in capital. It should be lower case  "var"

and it's missing  a ".value"  or  ".valueAsString" at the end 

 

 

Also, in this line :     if (CoreBankName !== null)


your IF statement is saying if that the obejct field "Is Not Null" it should be expressed if (CoreBankName !=="")

 

 

 

But If you wish to remind the user not to leave that field blank shouldn't it be :

 

if (CoreBankName=="")     

 

 

 

So I was thinking if your script should read instead something like :

 

var CoreBankName = this.getField("282_Core_Ref_Bank_Name").valueAsString;

if (CoreBankName=="") app.alert("Core Client Bank Name is required");

 

and then add your IF/Else statments like shown in line 3 below:

 

var CoreBankName = this.getField("282_Core_Ref_Bank_Name");

 if (CoreBankName=="") app.alert("Core Client Bank Name is required");

else if(CoreBankName  !=="") event.value = CoreBankName;

 

 

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 ,
Dec 09, 2019 Dec 09, 2019

Copy link to clipboard

Copied

I also forgot to ask if it actually matters where are you placing this code.

 

Is it a custom calculation script ? validation? custom format ? or as a java script that executes on a mouse up or mous on blur option, for example.

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 ,
Dec 09, 2019 Dec 09, 2019

Copy link to clipboard

Copied

Use "var", not "Var".

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 ,
Dec 09, 2019 Dec 09, 2019

Copy link to clipboard

Copied

LATEST

Just to clarify, even if you fix all syntax errors your code still won't work because you're not checking the correct thing, as I wrote before.

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