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

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

Explorer ,
Jan 07, 2022 Jan 07, 2022

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?

TOPICS
JavaScript , PDF forms
2.4K
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Jan 08, 2022 Jan 08, 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...

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 ,
Jan 08, 2022 Jan 08, 2022

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

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

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 ,
Jan 07, 2022 Jan 07, 2022

As validation script of "Name_Field" field use this:

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

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
Explorer ,
Jan 08, 2022 Jan 08, 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"

 

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 ,
Jan 08, 2022 Jan 08, 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...

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 ,
Jan 08, 2022 Jan 08, 2022

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

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 ,
Jan 08, 2022 Jan 08, 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?

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
Explorer ,
Jan 08, 2022 Jan 08, 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"

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 ,
Jan 08, 2022 Jan 08, 2022
LATEST

You can change the visibility of the label.

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
Explorer ,
Jan 08, 2022 Jan 08, 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;

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 ,
Jan 08, 2022 Jan 08, 2022

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

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

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
Explorer ,
Jan 08, 2022 Jan 08, 2022

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

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