Skip to main content
Inspiring
June 23, 2021
Answered

Forms: Telling another form field to be blank if this field is blank

  • June 23, 2021
  • 2 replies
  • 6139 views

I created a form set with many fields in rows where if the field is empty there is a default message in it to give the user info on how to fill it. Example:

// If field is blank, display this text 
if (!event.value) { event.target.fillColor = ["RGB", 255/255, 221/255, 170/255]; event.value = "Year, Make, and Model" } else { if (event.value) { event.target.fillColor = color.transparent; } }

 

In this row of several fields, my user wants to know if it's possible if the first row is intentionally left blank by filling in with a space character, could the remainng fields in that row all be made blank automatically?

 

Say there are seven fields... is possible to make fields two through seven say something in the script to the affect of the above format, but with an addtion of "if the first field in this row is intentionally blank, then make this field intentionally blank"?

This topic has been closed for replies.
Correct answer Nesa Nurani

Nesa, thank you for your help in this topic and others recently. I appreciate it. Here is what I've tried to come up with but I'm having syntax error reports and I'm not sure what the problem is. Acrobat has line 7 flagged with "Syntax Error 6".

 

// Look for value of first field in the row. If it's a blank space, then put a blank space in this field
if (this.getField("Vehicle Count 10.0").valueAsString==" ") event.value = " ";
// or if the field is blank, then add a light yellow fill color and put the text "address" in the field
else {if (!event.value) event.target.fillColor = ["RGB", 255/255, 221/255, 170/255];
event.value = "Address";
} else {
// or if the value is anything other than a space or a blank, then keep that text and make the fill color transparent
if (event.value) {
event.target.fillColor = color.transparent;
}

 

 


You are using curly brackets at wrong place,try like this:

if (this.getField("Vehicle Count 10.0").valueAsString==" ")
event.value = " ";
else if (!event.value){
event.target.fillColor = ["RGB", 255/255, 221/255, 170/255];
event.value = "Address";}
else if (event.value)
event.target.fillColor = color.transparent;

 

I assume you use script in calculation, as I already told you in previous post about "Address" last condition will overwrite color as soon as you change something in the file ( like check checkbox or enter value in another field...etc)

2 replies

try67
Community Expert
Community Expert
June 24, 2021

Yes, it is. The basic code is something like this:

 

if (this.getField("Name of first field in row").valueAsString=="") event.value = "";

Nesa Nurani
Community Expert
Community Expert
June 24, 2021

If he use space character it should be ==" ".

Inspiring
June 24, 2021

Giving it a try. My first field in the row is "Vehicle Count 10.0" (This is the label for the 10th row of the form). I put this addition in the script for the column for the address in that row. It has a placeholder of Address in case it's not filled in. So the thought would be that if Vehicle Count has a space as it's content, then this field will become a blank content. I tried this, entered a space in the Vehicle Count 10.0" field, and the word "Address" didn't disappear.

 

// If field is blank, display this text
if (!event.value) {
event.target.fillColor = ["RGB", 255/255, 221/255, 170/255];
event.value = "Address"
} else {
if (event.value) {
event.target.fillColor = color.transparent;
}
else {if (this.getField("Vehicle Count 10.0").valueAsString==" ") event.value = "";}
}

 

JR Boulay
Community Expert
Community Expert
June 23, 2021

Short answer is yes.

Long answer requires to know how fields are named.

Acrobate du PDF, InDesigner et Photoshopographe