Skip to main content
Known Participant
January 8, 2022
Answered

i need to show a field's text description only if the field is not empty

  • January 8, 2022
  • 4 replies
  • 3565 views

hi,

i have a form where i want to dispay the descriptive text if its field is not empty. if the field happens to be empty i want the text to be hidden. 
NAME ______________

if the user doesnt fill in the Name_Field, i do not want "NAME" to show.

i tried doing this by making Name_Text field and using condition to show "NAME" if Name_Field is not empty. i couldnt get it work. is there an easy way to get this done?

This topic has been closed for replies.
Correct answer Nesa Nurani

In the script i gave you just change event.value to "NAME" like this:

this.getField("Name_Text").value = event.value == "" ? "" : "NAME";

4 replies

Known Participant
January 8, 2022

thank you so much @Nesa Nurani @try67. i got it to work as i wanted

For "Name_Text" i used 
if (event.value) event.value = "NAME ";
and for "Name_Field" i used

this.getField("Name_Text").value = event.value == "" ? "" : event.value;

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
January 8, 2022

In the script i gave you just change event.value to "NAME" like this:

this.getField("Name_Text").value = event.value == "" ? "" : "NAME";

Known Participant
January 8, 2022

this does the work as well. thank you so much.

Bernd Alheit
Community Expert
Community Expert
January 8, 2022

> i need to show a field's text description only if the field is not empty

 

What want you show when the field is empty?

Known Participant
January 8, 2022

if "Name_Field" is empty i want "Name_Text" to be empty
if "Name_Field" has any data i want "Name_Text" to show "Name"

Bernd Alheit
Community Expert
Community Expert
January 8, 2022

You can change the visibility of the label.

try67
Community Expert
Community Expert
January 8, 2022

As the custom Format script enter the following code:

 

if (event.value) event.value = "NAME " + event.value;

 

This will prevent the value the user entered from actually being edited, and will also not add the fixed text multiple times each time you edit the field...

try67
Community Expert
Community Expert
January 8, 2022

Sorry, I thought this was a single field. Do you have one field for the label and another for the actual text?

Nesa Nurani
Community Expert
Community Expert
January 8, 2022

As validation script of "Name_Field" field use this:

this.getField("Name_Text").value = event.value == "" ? "" : event.value;

Known Participant
January 8, 2022

thanks for the quick response. appreciate it. tried the code but it copies the "Name_Field" data into "Name_Text" field. i would like the "Name_Text" field to show "Name" if any data has been entered into "Name_Field"