Copy link to clipboard
Copied
Hi all i'm very new to javascript and adobe forms.
I have a form in which if a data entry field is not used it is automatically populated with N/A. The N/A in the field is determinned by a calculation in a seperate field we'll call Field1. Depending on the value of Field1 the data entry field is either N/A and read only or the field is blank and the user needs to enter a value. When a value is entered i have the field validating the entry against a range, if its outside the range an app.alert notifies the users.
I'm having trouble getting the validation to ignore the N/A. it sees it as an entry outside the range and the alert box appears.
In the calculation box of Field1 i have
if (event.value>=3.335){
this.getField("Powder").value="N/A";
this.getField("Powder").readonly=true;
}
else{
this.getField("Powder").value="";
this.getField("Powder").readonly=false;
}
In the validation of the Powder field i have:
if (event.value>Upper || event.value<Lower && event.value!="" && event.value!="N/A"){
app.alert("Powder weight must be between "+Upper+"g and "+Lower+"g weight limit.",1);
event.target.textColor=color.red;
event.setFocus();
}
else{
event.target.textColor=color.black;
}
First thing I'd do is change this line:
if (event.value>Upper || event.value<Lower && event.value!="" && event.value!="N/A"){
To:
if ((event.value>Upper || event.value<Lower) && event.value!="" && event.value!="N/A"){
If that still doesn't solve it then you might need to share the file with us.
Copy link to clipboard
Copied
What is the format of the field?
A field formatted as Number cannot accept a text entry.
What is "Upper" and "Lower"?
For text fields there is a "toUpper()" and "toLower()" method.
Copy link to clipboard
Copied
I apologize, upper and lower are variables that define the range being validated. The field is formatted as none.
Copy link to clipboard
Copied
Small correction: It's toUpperCase() and toLowerCase()...
Copy link to clipboard
Copied
This line is incorrect:
event.setFocus();
It's also not how you reject a value. Use this instead:
event.rc = false;
Copy link to clipboard
Copied
I wanted the cursor to stay on the field if it was incorrect and also not lose the value if it was incorrect. If Incorrect data was entered and not fixed before completing the form I need that data to remain.
event.rc=false will revert the field to the previous value right? So if it’s blank and the wrong info entered it will go back to blank.
Copy link to clipboard
Copied
Yes, that is correct.
If you force the cursor to stay on the field the user won't be able to
enter an incorrect value, though...
Copy link to clipboard
Copied
the alert validation seems to work, if a value outside the range is entered the alert shows and sets text color to red. maybe the set focus isnt working as i expected and I can just take it out.
The problem is when the calculation places an N/A in the field the alert also shows and sets the N/A to red. I’d like it to set N/A in black text and not alert.
Copy link to clipboard
Copied
First thing I'd do is change this line:
if (event.value>Upper || event.value<Lower && event.value!="" && event.value!="N/A"){
To:
if ((event.value>Upper || event.value<Lower) && event.value!="" && event.value!="N/A"){
If that still doesn't solve it then you might need to share the file with us.
Copy link to clipboard
Copied
try67​ that worked, thanks!
I (incorrectly) assumed that using the && after the or statement would seperate the two statements on its own.