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 19, 2023

Hello Thom,

 

Thank you very much for your answer and your suggested solution. It seems to work exactly as I imagined. Your solution is much better and more practical.

 

So that you can understand where I had my scripts, I created and uploaded screenshots for you. The advantage of this variant is that the standard value automatically disappears when you click in the field. In your version you have to select the text and then delete it - but that's not so dramatic.

 

Thank you for your solution.