How can I validate a number falls with in a specified range?
I am using the number form element to have the user enter a number, I want to restrict what they can enter to between 0 and 600 or null if they don't need to enter anything. I started to use the lower and upper bound limits, but when they are used it puts the default to the median of the lower and upper, when default is left blank, so the user can not leave it blank.
I have started to try and use the validate workflow
Get Form Element Property
If Statement
But I can't seem to get a true statement to clear the form element error.
Are there any ideas on how to got about this differently.
thanks,
Tom
-
Hello Thomas,
It looks as though you are on the right track. It is possible to set a Default Value for the Number form element, and check the 'Required' checkbox but this won't allow users to enter no value.
In this case, you can use the If statement to check for =$form1.state.number1.value === 'undefined' and error as needed. If a value is present, you can then check its range: =$form1.state.number1.value.numeric >= 0 && $form1.state.number1.value.numeric <= 600 and error as necessary.
Take a look at the attached workflow for one method. You can also use Regular Expression Matches activity to achieve this.
Thanks, Stefan
0 -
Thank you Stefan!
I think I was missing the ".numeric" part of the expression to compare it to another number value. Also didn't realize you could combined statements using the &&
Is there somewhere in the help that defines how to write some of these statements?
Thanks again for your help!!
Tom
0 -
No problem, glad that I was able to help!
We don't currently, but I'll create a suggestion to improve our documentation around this.
0 -
I have another question around this same issue.
I have been testing what you uploaded, using my own data, and I think I have come to the conclusion that when you have a number field it does not recognize it as being 'undefined' in any state.
I tweaked what you sent so it should error if the field is left undefined, but it does not error.
What I am actually trying to do at the moment is on a change event show another field if the first numeric field is filled out. Which i thought i had, but if the user fills it out then removes the numbers in it the second field should blank out then disappear. Using the statement below I think should work but does not.
=$form1.state.number1.value === 'undefined'
Is there a different way to test if a number field on a form is blank?
Tom
0 -
Hello Thomas,
Thanks for catching my syntax error, this is the correct way to check for undefined:
=$form1.state.number1.value === undefined
Stefan
0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
5 Kommentare