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

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

Community Beginner ,
Aug 05, 2021 Aug 05, 2021

Copy link to clipboard

Copied

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?

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , How to , JavaScript , PDF forms , Print and prepress

Views

2.0K

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 , Aug 06, 2021 Aug 06, 2021

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

Votes

Translate

Translate
Community Expert ,
Aug 05, 2021 Aug 05, 2021

Copy link to clipboard

Copied

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

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

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

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

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?

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

Well, you have to skip buttons entirely, as they don't have a value property and trying to access it will result in an error.

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
Enthusiast ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

And what if user have button that he wants to print? Setting to defaultValue will make it non printable.

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

Buttons doesn't have a value or defaultValue.

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
Enthusiast ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

Yes, but if you use defaultValue with nthField code (as suggesteed by try67) button will be set to visible but no Printable.

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

Buttons doesn't have a property defaultValue!

May be that the OP want the script for text fields.

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

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

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

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

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

Sorry, but this code is not quite good. It will skip all non-text fields (including drop-downs, check-boxes, etc.), and will make all buttons visible, even if the author of the form originally set them up as not printable.

I would use this code, instead:

 

for ( var i = 0; i < this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	var f = this.getField(fname);
	if (f.type=="button") continue;
	if (f.valueAsString == f.defaultValue)
		f.display = display.noPrint;
	else f.display = display.visible;
}

 

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
Enthusiast ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

Ok now you just really nitpicking, to qoute Bernd:

The OP want the script for text fields.

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

They never wrote that. They wrote about the "default text" in the field. That can be a drop-down, too. For example, it can have the default value as "SELECT" and you don't necessarily want to print that.

Anyway, it's not nit-picking because that code will also have other unintended results, such as editing the visibility of all non-text fields.

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
Enthusiast ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

My point is you will always find a way to improve script but that just nitpicking.

I can also say your code is wrong too, OP can also have list box fields and your code will change it to not printable.

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 ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

Correct, if the default value is selected in it, it won't print. I don't think that's necessarily against their wishes, but we'll let them decide.

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 Beginner ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

LATEST

Awesome, thanks Nesa!  That works like a charm!

And to the debate, it's a scanned form for a bid sheet for my union, but with fillable text fields so people can save copies from the website I'm putting together to send out.  I'm constantly reworking it (want to get rid of those darn highlights so bad lol but I know that's a lost cause) and making it more user-friendly as kind of my prototype for how I'll do all the other forms, but I think it's nearly done.  I used a slightly modified version of Mz. Nurani's script (which worked fine out of the box) and it works beautifully.  I'd like to thank everyone here, and that business about buttons and drop-down boxes is an interesting point, and something I may have to consider for other forms.

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