Making a field required if a radio button or check box is selected when using a validation button

Community Beginner ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Hi

I've created a pdf form which has a validate button to check that certain required fields are filled in. 

I want to make an additional field (lump sum) required as part of the validation, but only if option 3 has been selected as the radio button. For option 1 and 2 it is not required.

I also want to make an additional field (AVC amount) required if a check box (Option B) is ticked. 

This is what I currently have which is working but what do I need to add for the above to work?

 

Thank you

 

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"||

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

{app.alert("Please complete all required fields which are highlighted in red.")}

TOPICS
How to, JavaScript, PDF forms

Views

326

Likes

Translate

Translate

Report

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

correct answers 1 Correct Answer

Adobe Community Professional , Apr 30, 2021 Apr 30, 2021
Try like this: if ( this.getField("Full name").value==""|| this.getField("Date of birth").value==""|| this.getField("Daytime phone number").value==""|| this.getField("Confirmation details correct").value=="Off"|| this.getField("Lump sum choices").value=="Off"|| this.getField("Bank name").value==""|| this.getField("Account name").value==""|| this.getField("Sort code (6 numbers)").value==""|| this.getField("Account number").value==""|| this.getField("Previous pension").value=="Off"|| this.getField...

Likes

Translate

Translate
Engaged ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

There is no way above code works.

You have error at the end and you are just making conditions, you are not doing anything with it.

Likes

Translate

Translate

Report

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 ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Hi

I only know a limited amount about Javascript which is why I have asked for help above in adding to it, so I'm not sure what error you are referring to but the script as it currently is, is working. If any of the fields listed above (which have been ticked as required as they are always required) have been left blank/no button selected and the validate button on the pdf is pressed then the message appears as a popup. This is all I need it to do, but I need to add the fields mentioned above which are only required depending on other answers.

The final part of the script I have already had help with as this was based on the field only being required if one of 5 of 7 options was selected. I have tried to adapt this for what I need to add but have not had any luck in being able to add the additional fields that I mention above. I would appreciate any advice on being able to add these. Thank you.

Likes

Translate

Translate

Report

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
Engaged ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Try paste code above in your field and then try exit javascript editor.

Likes

Translate

Translate

Report

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 ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Are you asking me to do that so the javascript editor will highlight an error? The code above was copied from the javascript editor and no error was highlighted. It has been in use and working as needed for a number of weeks.

As I said above I need help adding to it now please, if anyone is able to, so it includes the additional fields that are only required depending on the answer to other questions - I'm unsure how to add these so that the message only pops up if the specific conditions mentioned above are met.

 

Thank you

Likes

Translate

Translate

Report

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
Engaged ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Could you share your file here?

Likes

Translate

Translate

Report

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 ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Yes, it's a public form so I have attached an amended copy.

The validate button is at the end of the form where the javascript is.

For Q2 if they pick option 3 of the radio buttons I need it to pick up that the lump sum amount must also be filled in. An answer to Q2 is required.

For Q2a I need it to pick up that if the check box for option B is ticked then the AVC fund amount must also be filled in. An answer to Q2a is not required.

Thank you 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Add this to the code:

(this.getField("Option B").valueAsString != "Off" && this.getField("AVC fund amount").value == "")||
(this.getField("Lump sum choices").valueAsString == "Option 3 Converting some pension to lump sum" &&  this.getField("lump sum amount").value == "")

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thank you for sending the coding - when I have tried to add it though, it comes up with a syntax error. I tried adjusting the spaces in between in case I was reading it wrongly ant the parentheses too but that didn't make a difference. Could you please help? I've attached a snip below so you can see the placement etc. Thank you.

Hannah5CAF_0-1619773002008.png

 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 30, 2021 Apr 30, 2021

Copy link to clipboard

Copied

I can't see entire code, but if I had to guess I would say you are missing another ) before app.alert

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hi, thanks but that hasn't worked. I've copied the full code below if you could help please? Thank you so much.

if (
this.getField("Full name").value==""|| this.getField("Date of birth").value==""||
this.getField("Daytime phone number").value==""||
this.getField("Confirmation details correct").value=="Off"||
this.getField("Lump sum choices").value=="Off"||
this.getField("Bank name").value==""||
this.getField("Account name").value==""||
this.getField("Sort code (6 numbers)").value==""||
this.getField("Account number").value==""||
this.getField("Previous pension").value=="Off"||
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"||
(this.getField("Option B").valueAsString != "Off" && this.getField("AVC fund amount").value == "")||
(this.getField("Lump sum choices").valueAsString == "Option 3 Converting some pension to lump sum" && this.getField("lump sum amount").value == "")
this.getfield("Date of event").value==""&& this.field("Date of event").required==true))
{app.alert("Please complete all required fields which are highlighted in red.")}

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 30, 2021 Apr 30, 2021

Copy link to clipboard

Copied

Try like this:

if (
this.getField("Full name").value==""|| this.getField("Date of birth").value==""||
this.getField("Daytime phone number").value==""||
this.getField("Confirmation details correct").value=="Off"||
this.getField("Lump sum choices").value=="Off"||
this.getField("Bank name").value==""||
this.getField("Account name").value==""||
this.getField("Sort code (6 numbers)").value==""||
this.getField("Account number").value==""||
this.getField("Previous pension").value=="Off"||
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"||
(this.getField("Option B").valueAsString != "Off" && this.getField("AVC fund amount").value == "")||
(this.getField("Lump sum choices").valueAsString == "Option 3 Converting some pension to lump sum" && this.getField("lump sum amount").value == "")||
(this.getfield("Date of event").value==""&& this.field("Date of event").required==true))
{app.alert("Please complete all required fields which are highlighted in red.")}

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

That works great thanks - it doesn't highlight the new required fields, but I can change the pop up wording so it still works. Thank you for your help.

 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 30, 2021 Apr 30, 2021

Copy link to clipboard

Copied

LATEST

If you want to make field required, add script to mouse up event of radio/checkbox to make them required or not required when radio/checkbox is checked/unchecked.

Likes

Translate

Translate

Report

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