Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

script/validation question

Avatar

Former Community Member
I have a form with fields called mileage and time, if the person filling in the form misses the field time, and enters a number into the field time, I want a message to pop up saying they need to first enter their mileage (up to 100.0).

I know how to check for the range and make the totals equal no more than the allowed maximums, but I don't know how to make one field dependant on another field.

Suggestions?

Thanks.
10 Replies

Avatar

Former Community Member
Put a validation script on the validate event in time:



if (mileage has a value)

true

else

false

Avatar

Former Community Member
I must be doing something wrong, it's not working - in the Validate section I have -



if (NumericField5)

true

else

false



but it results in an error -

------------

Script failed (language is formcalc; context is xfa[0],form[0],form1[0],#subform[0],#area[4],NumericField3[0])

script=if (NumericField5)

true

else

false

Error: syntax error near token 'true' on line 2, column 8.

------------

Avatar

Former Community Member
Not sure how to do it using FormCalc, try switching to Javascript. And in the if clause you'll want to check the rawValue of NumericField5. It'll be either null or 0 if nothing has been entered, I forget which, but doing that should get it going for you.



H.

Avatar

Former Community Member
Hmm, no luck so far. Here's what I've tried, in javascript mode -

-------------

if (rawValue(NumericField5))

true

else

false

-------------

and also

-------------

if (rawValue(NumericField5==NULL))

true

else

false

------------

I really have no idea what I'm doing. rawValue is not on the drop-down list of functions. Both seem to validate without errors, but there is no effect on the form, like the script is ignored.

Avatar

Former Community Member
Try something like:



if (NumericField5.rawValue==0 || NumericField5.rawValue==null) {

false;

} else {

true;

}



It probably seems like the script is ignored because you don't have teh option turned on in Acrobat to show Javascript errors. In Acrobat go to Edit->Preferences->Javascript and it's call something along the lines of "Show console on errrors".



H.

Avatar

Former Community Member
Thankyou, that works very well. So now I have tried the same script on another field, like this -

-------------

if (NumericField1.rawValue>3 || NumericField3.rawValue>2 || NumericField5.rawValue>100) {

false;

} else {

true;

}

-------------

My intent is to have a field that is optional to begin with become required if any of those 3 fields above have a number greater than the ones shown above. Just for sh#@% & giggles I tried with true; and false; reversed.



But once again, get no response, like it is just ignored (in Preview). I did open Acrobat Pro and check the Preferences/Javascript section, checked the boxes for all the debugger stuff. When I open the doc in Acrobat it gives no errors.

Avatar

Former Community Member
Well the logic of your script is a little off. That says that if any one of those other three fields have values greater than those thresholds then regardless of what is typed into this field it should always fail validation. Something like this may work a bit better:



if ( (NumericField1.rawValue>3 || NumericField3.rawValue>2 || NumericField5.rawValue>100) && (this.rawValue==null || this.rawValue==0) ) }

false;

} else {

true;

}



Don't forget, you can also put xfa.host.messageBox() or app.alert() calls in your script to see which branches of logic they are taking and make debugging easier.



H.

Avatar

Level 4

I have a similar yet different question.  I want to have a numeric field where you cannot put in a number greater than 4.  So the value in the field can be from 0 to 4 but not greater.  Can I do that with a validation pattern or do I have to add a script to it. and if I do what would it be?

Thanks tons!!!

Jodi

Avatar

Former Community Member
Thankyou for the help, but it still does not seem to work. I don't know how/where to insert the calls you show. I have the form available online if anyone is interested in looking at it - there is also some odd behavior in the validation of two other fields - mileage and travel time. The address is http://www.simradusa.com/b&g%20warranty%20claim%20form.pdf

Avatar

Former Community Member
I have added the alert call to the script and that helps considerably -



if ((LaborTime.rawValue>3 || TravelTime.rawValue>2 || Mileage.rawValue>100) && (this.rawValue==null || this.rawValue==0)) {

false;

app.alert("Please provide your ETP number for full reimbursement.");

} else {

true;

}



But I still have the odd problems with the validation of the TravelTime field.



Any suggestions?