Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

**Help Needed** Custom Pop-up Message for Field Validation

Avatar

Level 2

I have a form I am working on. But I can't figure out how to make the field have a pop-up message if someone enters .40 instead of 40. I want the field to block anyone from putting in .40 and only allow them to enter numbers straight up (i.e. 40).

If the user enters anything BUT straight up numbers, I want the pop-up message to say "Input the mileage rate as the number of cents per mile (i.e., 30 instead of .30)."

Thank you in advance for any help!

The form is attached........

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

You can add this script to the exit event of the field. If they enter a value of < 1 then a message will appear and the code will multiply the value by 100 to make it cents and not dollars.

if (this.rawValue < 1) {
app.alert("Enter your milage rate in cents 40 and not dollars .40");
this.rawValue = this.rawValue * 100;
}

If you woudl rather you can put the cursor back into the field and allow the user to remedy the entry before moving on. To do this use the command:

xfa.host.setFocus(this);

Hope that helps

Paul

View solution in original post

4 Replies

Avatar

Correct answer by
Former Community Member

You can add this script to the exit event of the field. If they enter a value of < 1 then a message will appear and the code will multiply the value by 100 to make it cents and not dollars.

if (this.rawValue < 1) {
app.alert("Enter your milage rate in cents 40 and not dollars .40");
this.rawValue = this.rawValue * 100;
}

If you woudl rather you can put the cursor back into the field and allow the user to remedy the entry before moving on. To do this use the command:

xfa.host.setFocus(this);

Hope that helps

Paul

Avatar

Level 2

This worked! Now if I want to add the xfa.host.setFocus(this);, where in the code do I put it?

Avatar

Former Community Member

If you are putting that in I assume that you want the user to correct the error. So simply replace the line:

this.rawValue = this.rawValue * 100;

with the setFocus line.

Paul

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----