Skip to main content
Participating Frequently
October 18, 2023
Answered

Do not print field if value is the same

  • October 18, 2023
  • 1 reply
  • 1409 views

Hello everyone,

 

Maybe someone has a solution for my problem. In a form I have several fields that are defined by the following javascript

 

The default value is: "Click or tap here to enter text."

 

the first code action:

Activate field:

 

if(event.target.value==event.target.defaultValue) event.target.value="";

 

 

the second code action:

Deactivate field:

 

if(event.target.value=="")event.target.value=event.target.defaultValue ;

 

 

This means that the placeholder in the field says “Click or tap here to enter text.”. If you click on the field something else can be written. If nothing is changed, the placeholder appears again.

 

Now I woudl like to have this:

If the field is not filled with new text, i.e. if the default value is not changed, the field should not be printed. It should only be printed when the value changes.

 

I tried with this expression:

 

var oFld = this.getField(FieldName);
oFld.display = (oFld.value == oFld.defaultValue)?display.noPrint:display.visible;

 

but it doesn't work. The field is still printing

 

Maybe someone has a solution?

 

Thank you very much

This topic has been closed for replies.
Correct answer Thom Parker

Where is this code? In what event script?

It is a bad idea to set the default to help text.  

A better solution is to use a custom format script to display the help text.

 

Format Script:

if(event.value == "")

{

    event.value = "Click or tap here to enter text.";

    event.target.display = display.noPrint;

}

else

    event.target.display = display.visible;

 

Now you don't have to do bizare things to fixup the field value. 

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
October 18, 2023

Where is this code? In what event script?

It is a bad idea to set the default to help text.  

A better solution is to use a custom format script to display the help text.

 

Format Script:

if(event.value == "")

{

    event.value = "Click or tap here to enter text.";

    event.target.display = display.noPrint;

}

else

    event.target.display = display.visible;

 

Now you don't have to do bizare things to fixup the field value. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
DimiDNPAuthor
Participating Frequently
October 20, 2023

Hello Thom,

 

maybe you also have the solution for a drop down menu. If "Select an item" (default value) is selected, the field should not be printed. I changed "Click or tap here to enter text" in "Select an item" in your code. But unfortunately it doesn't work.

 

I have also attached a screenshot.

 

Thank you

Thom Parker
Community Expert
Community Expert
October 20, 2023

For  a dropdown you can use a validation script to set the visibility. 

It always a good idea to also set the "Commit selection immediately" option.

 

Here's a custom validation script.

event.target.display = (event.value == event.target.defaultValue)?display.noPrint:display.visible;

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often