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"?
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
...Copy link to clipboard
Copied
Short answer is yes.
Long answer requires to know how fields are named.
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 = "";
Copy link to clipboard
Copied
If he use space character it should be ==" ".
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.
// 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 = "";}
}
Copy link to clipboard
Copied
Where did you place this code?
Copy link to clipboard
Copied
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.
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.
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.
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" .
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.
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;
}
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)
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...
Copy link to clipboard
Copied
Sorry I'm not sure what exactly is problem on photo?
Copy link to clipboard
Copied
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!