• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

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

Contributor ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

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"?

TOPICS
PDF forms

Views

3.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 28, 2021 Jun 28, 2021

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

...

Votes

Translate

Translate
Community Expert ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

Short answer is yes.

Long answer requires to know how fields are named.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

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

 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

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.

 

Screen Shot 2021-06-24 at 10.19.34 AM.png

// 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 = "";}
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

Where did you place this code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

Screen Shot 2021-06-24 at 10.50.56 AM.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

This doesn't make sense... What is the name of the field you want to clear, then?

Also, you should not be using the Format event. Use Validation or Calculation.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

The point of this form is that there are placeholder words that show up in each field with a yellow highlight if the form is new. The user clicks in a field and enters the information which then drops the yellow highlight to become normal with the new information. By entering a space, the field then becomes blank. 

 

The client wanted to know if entering blank in the first column would automatically make all the items in that row blank instead of manually doing a blank in each row. 

 

You can see that the first objective was achieved in the custom script window. Why wouldn't modifying this also be in the custom script window?

 

The field I wanted to clear in a test is "Address 10". See the field name in the grid in the example above. That's the field that is being edited.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

Actually, I realized that if I set the condition of the value of the first cell with " ", then the result of the desired cells should be " ", not "". 

 

So this is my code example, but it's still not working.

// 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 = " ";}
}

 

So that a space would result and not be "no content" so that the yellow background and "Address" doesn't fill the cell. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

It won't work the way you imagine it, your second condition will overwrite your first when something is changed in file and will leave "Address" with transparent background, and your third condition will never take place, because second will always be active.To fix your 3rd condition put it in first place and to your second condition add if event.value is not "address" .

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 25, 2021 Jun 25, 2021

Copy link to clipboard

Copied

I wondered if there was an order this would need in order to work. Thanks, Nesa for the advice. I'll try that direction. There are so many instructions happening throughout the document that I thought there might be a chance some would cancel others in the wrong way.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

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;
}

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

That works, Nesa. I'm a low-level Javascript user so I appreciate your looking at my code and seeing where I'm not setting it correctly. Here are the results where I put your code in two fields of the form...Screen Shot 2021-06-29 at 8.18.57 AM.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

Sorry I'm not sure what exactly is problem on photo?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

LATEST

It's not a problem, it's your solution in action! Note that your last comment is the correct answer now. Thank you!

 

I entered a blank space in the first column in row 10 and the two fields above my red note are the ones I tested the code in. It works!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines