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

PDF form - Validate button coding when required status is dependent on radio button selection

Community Beginner ,
Mar 30, 2021 Mar 30, 2021

Hi

I have created a form with a number of fields that are required. In order for the person completing the form to check they have completed everything they have to I created a validate button with the below coding so a message pops up if they haven't completed all the fields. 

if (

this.getField("Partnership status").value=="Off"||
this.getField("Question one").value=="Off"||
this.getField("Question two").value=="Off"||
this.getField("Question three").value=="Off"||
this.getField("Question four").value=="Off"||
this.getField("Question five").value=="Off"||
this.getField("Question six").value=="Off"||
this.getField("Declaration confirmation").value=="Off"
)
{app.alert("Please complete all required fields which are highlighted in red.")}

 

I have been asked however to make an additional field required "Date of event" depending on the answer given to "Partnership status" which is a group of radio buttons. To do this I've added to each radio button the following code with true or false depending on the action.

this.getField("Date of event").required = true;

 

I'm not sure though how to then add this in to the code for my validation button so that it can tell if this field is required or not and therefore needs completing or not. Thank you for any help with this.

 

 

TOPICS
How to , JavaScript , PDF forms
2.2K
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 ,
Mar 30, 2021 Mar 30, 2021

Not sure if I understand it right , but you can implement into code to check if field is empty and required.

(this.getField("Date of event").value == "" && this.getField("Date of event").required == true);

 

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 ,
Mar 30, 2021 Mar 30, 2021

Not sure if I understand it right , but you can implement into code to check if field is empty and required.

(this.getField("Date of event").value == "" && this.getField("Date of event").required == true);

 

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 ,
Mar 30, 2021 Mar 30, 2021

Thanks, I've tried this but unfortunately the warning message isn't coming up for the validate button when the field has been made required but has been left blank.

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 ,
Mar 30, 2021 Mar 30, 2021

Can you share  your file?

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 ,
Mar 30, 2021 Mar 30, 2021

Hi

Yes, it will be a public form so I've attached a copy. The validation has also stopped working now except for the Full name, Date of birth, and telephone number fields so if there is a better way to do the script for this to incorporate the Date of event field being required/or not, and completed or not, I'm happy to change it. Thanks for your help.

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 ,
Mar 30, 2021 Mar 30, 2021

My code will work but you have error in your script, change field name "Daytime telephone number" to

"Daytime phone number".

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 ,
Mar 31, 2021 Mar 31, 2021
LATEST

That has all worked perfectly, 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