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

Do not print field if value is the same

Community Beginner ,
Oct 18, 2023 Oct 18, 2023

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

TOPICS
JavaScript , PDF forms
1.0K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Oct 18, 2023 Oct 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
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 ,
Oct 18, 2023 Oct 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
Oct 19, 2023 Oct 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.

Translate
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 ,
Oct 20, 2023 Oct 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

Translate
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 ,
Oct 20, 2023 Oct 20, 2023
LATEST

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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