Skip to main content
Bastaw
Participating Frequently
November 3, 2018
Answered

Help getting field validation to ignore N/A

  • November 3, 2018
  • 2 replies
  • 1509 views

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;

}

This topic has been closed for replies.
Correct answer try67

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.


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.

2 replies

try67
Community Expert
Community Expert
November 3, 2018

This line is incorrect:

event.setFocus();

It's also not how you reject a value. Use this instead:

event.rc = false;

Bastaw
BastawAuthor
Participating Frequently
November 3, 2018

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.

try67
Community Expert
Community Expert
November 3, 2018

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...

Inspiring
November 3, 2018

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.

Bastaw
BastawAuthor
Participating Frequently
November 3, 2018

I apologize, upper and lower are variables that define the range being validated.  The field is formatted as none.