Expand my Community achievements bar.

SOLVED

Enforcing minimum/maximum of grand total (Validation)

Avatar

Level 2

I have a form with several fields to which users (employees) need to enter their working hours. The grand total (a read only field) must be 40. I relied on FormClac to enter the SUM function.

I want to prevent users from submitting the form if the total is less or more than 40 but I do not want them to constantly get an error message (while filling out the form) if the grand total is not 40. I want the error message to appear only if they try to submit the form and to prevent them from sending the form if the grand total is not 40.

I do not really know much about JavaScript so I would really appreciate it if someone could send me an example.

Thanks,

Yaniv

1 Accepted Solution

Avatar

Correct answer by
Former Community Member
6 Replies

Avatar

Level 2

Ok. I was able to figure this one out (http://forums.adobe.com/message/1944044#1944044 - pguerett) on validate:

if ((this.rawValue >= 0) && (this.rawValue <= 40)){

   true

} else {

   false

}

However, how can I change the error message from Validate failed to something else. How do I insert the alert into this script?

I would greatly appreciate your help.

Avatar

Correct answer by
Former Community Member

Avatar

Level 2

Yes. Thank you again Steve!

if ((this.rawValue >= 0) && (this.rawValue <= 40)){
true
} else {xfa.host.messageBox("The total cannot be more than 40!");
false
}
But the validate error message also pops up after my xfa message?! Is there something more I am supposed to do?

Avatar

Former Community Member

Remove 'true' and 'false' from your validation script. If you look at the Value tab for the object, you probably have Error checked for the Validation Script Message. I believe the presence of 'true' in your validation script causes the built-in validation to fire.

How about...

if (!(this.isNull || this.rawValue.length == 0)) {

     if (this.rawValue > 40) {

          xfa.host.messageBox("The total cannot be more than 40!");

     }
}

Avatar

Level 2

OK. The script didn’t work. It did not identify the error and even when I unchecked the Validation Script Message, I still got the Validation message.

But your answer did give me the solution. I took my xfa message and placed it in the validation message box and now the user gets ONE error message and with the message I wanted to send him.

I am trying to do the same thing with the Sunday date issue. I added a false commend to prevent submission and placed the xfa message in the Validation box. In this case, for some reason the validation doesn’t work.

if (!(this.isNull || this.rawValue.length == 0)) {
     if (this.rawValue != "Sun") {
          xfa.host.messageBox("The selected date is not a Sunday.");
              false
          }
}

I didn’t sleep all night trying to fix these issues and now it all looks so much better… I am simply grateful for your help!!!

Avatar

Level 2

I of course had to change the Type to read only but since user override is not allowed I don’t see why this should be a problem.

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] ----