Expand my Community achievements bar.

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

Validation of form fields

Avatar

Former Community Member
Hi,

I have a form that is used to fill in test results.

Now I want to validate that the results in the form field

are in accordance with the required value.

e.g. required value for hardness from 75-80.



<75 or >80 is incorrect, 75-80 is correct



How can I check this and can I open a message box that shows

that the user typed in an incorrect result??



thanks

A. Wimmer
7 Replies

Avatar

Former Community Member
There are two things you need to do: Create some script to validate, and add a validation script message.



To add the validation script, select the field that you want to validate, open the script editor window, select the "validate" event, set the language to "JavaScript", and use this as the validation script:



this.rawValue >= 75 && this.rawValue <= 80;



This little bit of JavaScript will evaluate to true if the value in the field is within the range of 75 through 80.



If you preview the form now, you'll see a generic error message that validation failed when you enter an invalid value and move the selection off of the field.



To customize this message, open the Object Inspector's Value tab with the field selected, and type in your own message in the Validation Script Message box.

--

SteveX

Adobe Systems

Avatar

Former Community Member
Thank you!



Works good and I can imagine how to change the script

for my other needs.

But can you tell me how I can display a positive number

e.g. +6, in a form field (number-field?)

(I use the german edition of designer, so I don't know

exactly the english term for the form field.)

The help-files always tell me that a + in front of a positive number

is not necessary.

I know this, but sometimes I need it because of the "look".



Hope you can help me!



A.Wimmer

Avatar

Former Community Member
You wouldn't be able to set the data of a numeric field to '+'something, since the Numeric only allows numbers. But you could set the display pattern of a numeric field to something like:



'+'zzz9



After that, if the user entered 66, for example, the field would display +66.



Not sure if that meets your need.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Thank's for the quick help.



The Problem with the above solution is, if I have a required range from -10 up to +10, I will always have a "+" in front of the number. e.g. for a negative value:

b +

-10



Is there a way to do this with a script that attaches a "+" if the value is positive and a "-" if the value is negative?



I'm so close to the solution for my "perfect" Test-report-form, it's just this "+" ... :-(



A.Wimmer

Avatar

Former Community Member
Try this script in the exit event of the numeric field. If the value entered is -, then it will show a -. If it's 0 it will show no sign. If it's + it will show a +. Seems to work with limited testing here anyhow.



if (this.rawValue > 0) {

this.format.picture.value = "'+'zzz9";

} else {

this.format.picture.value = "";

}



Chris

Adobe Enteprise Developer Support

Avatar

Former Community Member
Wow!

Looks good and works :-)

For someone like me who has no experience with javascript

these informations/hints/script are a good way to learn how it works.



Do you know any online-resorces for newbies according javascript?



Thank you for the quick help, Chris.



A.Wimmer

Avatar

Former Community Member
Well, for standard JavaScript there are tons of tutorials to be found on the web. For more specific to Designer forms, the XML Form Object Model reference found at the Designer Developer Center is good to have: http://www.adobe.com/products/server/readerextensions/main.html



You can also find a link to some form samples there.



Chris

Adobe Enteprise Developer Support