Skip to main content
Eli-zabelle
Inspiring
May 21, 2017
Answered

Wanting fields with default values to hide

  • May 21, 2017
  • 3 replies
  • 776 views

I'm an absolute beginner with JS. I'm trying to get multiple fields holding default values to hide when I use a checkbox.  This is my code 

var nHide = event.target.isBoxChecked(0)? display.hidden:display.visible; 

var f = this.getField("TitreNom4L"); if(f.value==f.defaultValue) f.display = nHide;

However, all the fields hide, even when the default value has been replaced. Please help me with what I am doing wrong.

Note : At first, i wanted it as an action just before print, but nothing happened at all. At least with a checkbox the fields do react.

Thank you.

This topic has been closed for replies.
Correct answer Eli-zabelle

I was able to solve my problem with findings after I browsed discussions here. My working code, which doesn't print a default text and colors it gray, but makes the new entry printable, black and uppercase, is now this one :

in custom format script :

// If field is blank, do not print this field 

event.target.display = event.value ? display.visible : display.noPrint; 

 

// If field is blank, display this text 

if (!event.value) event.value = "Receiver", event.target.textColor = color.gray;

else

event.value = event.value.toUpperCase(), event.target.textColor = color.black;

To make it work properly, I must eliminate all default text from the options tab. However, my new problem is that it can't apply to one of my fields, a dropdown list, because this one can't be without a default text. And I have tried to alter my code to make it work but couldn't come up with a solution.

Any ideas on how to make a similar code for a dropdown list?

Thank you.

---------

I'm replying to myself again...if it should be useful for someone. I found my second solution using an array to represent my dropdown list.

var multipleValues = [];

multipleValues[0]="Prov";

multipleValues[1]="QC";

multipleValues[2]="ON";

multipleValues[3]="NS";

if(event.target.value == multipleValues[0])

event.target.display = display.noPrint, event.target.textColor = color.gray;

else

event.target.display = display.visible, event.target.textColor = color.black;

3 replies

Eli-zabelle
Eli-zabelleAuthorCorrect answer
Inspiring
May 31, 2017

I was able to solve my problem with findings after I browsed discussions here. My working code, which doesn't print a default text and colors it gray, but makes the new entry printable, black and uppercase, is now this one :

in custom format script :

// If field is blank, do not print this field 

event.target.display = event.value ? display.visible : display.noPrint; 

 

// If field is blank, display this text 

if (!event.value) event.value = "Receiver", event.target.textColor = color.gray;

else

event.value = event.value.toUpperCase(), event.target.textColor = color.black;

To make it work properly, I must eliminate all default text from the options tab. However, my new problem is that it can't apply to one of my fields, a dropdown list, because this one can't be without a default text. And I have tried to alter my code to make it work but couldn't come up with a solution.

Any ideas on how to make a similar code for a dropdown list?

Thank you.

---------

I'm replying to myself again...if it should be useful for someone. I found my second solution using an array to represent my dropdown list.

var multipleValues = [];

multipleValues[0]="Prov";

multipleValues[1]="QC";

multipleValues[2]="ON";

multipleValues[3]="NS";

if(event.target.value == multipleValues[0])

event.target.display = display.noPrint, event.target.textColor = color.gray;

else

event.target.display = display.visible, event.target.textColor = color.black;

JR Boulay
Community Expert
Community Expert
May 22, 2017

Place default texts as "default value" in your text fields, and place this JavaScript as a Custom Format Script:

sValDefo = event.target.defaultValue;

if (!event.value) {

    // manage value

    event.value = sValDefo;

    // manage text color

    event.target.textColor = event.value == sValDefo ? color.ltGray : color.black;

}

Acrobate du PDF, InDesigner et Photoshopographe
Inspiring
May 22, 2017

Where did you place that code - what field and what event (e.g., Mouse Up event of a check box)