Skip to main content
Participating Frequently
Dec 9, 2019 7:44 PM UTC
Question

Create message for required fields

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

This topic is closed to new replies. Start a new post to keep the conversation going.

10 replies

try67
Community Expert
Community Expert
Dec 9, 2019 8:12 PM UTC

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.

Translate
ls_rbls
Community Expert
Community Expert
Dec 9, 2019 8:16 PM UTC

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?

Translate
Technical Generalist
try67
Community Expert
Community Expert
Dec 9, 2019 8:17 PM UTC

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.

Translate
ls_rbls
Community Expert
Community Expert
Dec 9, 2019 7:53 PM UTC

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

Translate
Technical Generalist