Skip to main content
Participant
August 6, 2021
Answered

make a field switch from "Visible" to "visible but doesn't print" if the default text is in field.

  • August 6, 2021
  • 1 reply
  • 4182 views

I have a question about Adobe Acrobat Pro DC if anyone can help.
I don't think it's too advanced, but I'm a bit out of the loop. I have a form that I want people to be able to fill out, and I want there to be default text displayed that they can click the field and input their own.
Using simple Java for the "click and it disappears" part
if (event.target.value == event.target.defaultValue){
event.target.value = "";
}
And the inverse for clicking off of it if the field is blank.
My problem is that I want the default text there so that people can know what they should input, but not all fields are required to be filled in if not needed. Is there a way to check for a print event or something or to make a field switch from "Visible" to "visible but doesn't print" if the default text is left in the field?

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

No. As I said, you have to skip them in the loop, so their display property is not changed.


Ok guys no need to argue,here is updated script:

for ( var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
if (this.getField(fname).type == "text" && this.getField(fname).value == this.getField(fname).defaultValue)
this.getField(fname).display = display.noPrint;

else this.getField(fname).display = display.visible;}

1 reply

Nesa Nurani
Community Expert
Community Expert
August 6, 2021

Yes you can use "Will print" event.

While in 'Prepare form' tool, click on 'More'->'Document Actions'-> and select 'Document Will Print', now click on 'Edit' and paste script inside (replace "Default text goes here" with your text):

for ( var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
if ( this.getField(fname).value == "Default text goes here")
this.getField(fname).display = display.noPrint;

else this.getField(fname).display = display.visible;}

try67
Community Expert
Community Expert
August 6, 2021

- Since not all fields have the same default value necessarily it's better to use the defaultValue property then a hard-coded string.

- You need to add a condition to turn the field's display back to visible, or it will never print once you try to do it with an empty field, even if you fill it in later on.

Nesa Nurani
Community Expert
Community Expert
August 6, 2021

I added line to make it back to visible but I'm not so sure about defaultValue.

Wouldn't set it to defaultValue also make other text fields that doesn't have set default value and buttons...etc to noPrint?