Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Value Range for numeric field

Avatar

Level 1

I'm fairly new to LiveCycle, I've used it to make forms for a bit, but am now hoping to make the forms much more advanced.  I'd like to know the best way to set a value range/parameter for a numeric field? I want the filler to be restricted to a range of $300 to $10,000 and if they try to enter below or above that value they would receive an error message.  I've looked at all the beginner material and am trying to get introduced to FormCalc and/or JavaScript but not fully comprehending the best/complete method (any guidance on where to start is also greatly appreciated).

Thanks, Ed

5 Replies

Avatar

Former Community Member

You woudl need to write your own validation script to ensure that the value entered fell in that range. In your script you can return a true or false value. Put this code on the validate event:

if ((300 < this.rawValue) && (this.rawValue < 10000)){

   true

} else {

   false

}

Then on the Object/Validate Tab palette put an error maessage that you want to have displayed in teh Validation Script Message box.

Paul

Avatar

Level 1

Thank you, I was able to get that to work just fine.

Avatar

Level 1

My only concern is that if I put in an invalid number, the warning comes up but the number is still in the form. Any thoughts, or is there still further code I need to add?

Avatar

Former Community Member

Your code could blank out the field if it was invalid. Just add this.rawValue = "" before the false

The only issue is that if the field is now blank then I will not know why my entry was invalid. Be aware that the user will not be able to submit until that validation is cleared out.

Paul

Avatar

Level 4

if (((300 < this.rawValue) && (this.rawValue < 10000)) || (this.rawValue == null)){

   true

} else {
this.rawValue = null;

app.alert("Please enter a value between 300 and 10.000")

}

I changed some things though... ^^

If you want 300 / 10 000 to be true too then set <= instead of <.

You can also change the app.alert message as you want.

If you don't add the null in the beginning you might get an error message if it's on the validate event. If it's in the exit there shouldn't be a problem...

Though this is just a little different from Paul's original solution.