Skip to main content
May 31, 2017
Answered

Form validation field help

  • May 31, 2017
  • 1 reply
  • 958 views

Hi, I have a document I am preparing and one of the form fields essentially adds up 5 other fields (percentages); is there a way I can force that field to equal 100%? Perhaps an error message can appear if they are over or under so they will be alerted to go back and fix it?

If this makes the question easier to understand ~ I need employees to describe tasks that equal 100% of their daily tasks. How I have it set up now they can go over or under 100% and I would like to have an alert for them. I have never used Adobe Acrobat DC but certainly this can be done (?).

Thanks!

Tracy

This topic has been closed for replies.
Correct answer try67

How can I add a condition that checks for those things? I have tried so many things with the validation fields trying to get the warning to only show up at the end to no avail.

Thank you for getting back to me.


This code should do the trick (I assumed the fields are named Perc1 to Perc5... You can change it to match their actual names, of course):

if (event.value>100) app.alert("Warning! The combined value must not exceed 100%.",1);

else {

    if (this.getField("Perc1").valueAsString!="" && this.getField("Perc2").valueAsString!="" && this.getField("Perc3").valueAsString!=""

        && this.getField("Perc4").valueAsString!="" && this.getField("Perc5").valueAsString!="" && event.value!=100) {

            app.alert("Warning! The combined value must equal 100%.",1);

    }

}

1 reply

May 31, 2017

So it's allowing me to have an error message saying "the value must be greater than or equal to 100 and less than or equal to 100".

But it isn't allowing me to put a custom note in that explains it better. Is there a way I can edit the error message?

try67
Community Expert
Community Expert
May 31, 2017

As the custom validation script of the field you can use something like this:

if (event.value!=100) app.alert("Insert your custom message here.",1);

Note that this is probably not a good idea, because this message will appear each time the user edits one of those fields... You might want to add a condition that checks that all the fields are filled-in first before showing it, and/or if the value exceeds 100, which is always wrong.

May 31, 2017

How can I add a condition that checks for those things? I have tried so many things with the validation fields trying to get the warning to only show up at the end to no avail.

Thank you for getting back to me.