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

Make Field Required if Another Field's Value Changes from "Please enter Job Responsibility"

Community Beginner ,
Apr 21, 2021 Apr 21, 2021

Copy link to clipboard

Copied

I have a form I am developing for Employee Evaluations where the manager is given space to list up to 10 job responsibilities. HR is requesting that the comment section under a job responsibility is mandatory should the field's placeholder text change. 

In essence, I need field "R1 - Comments" to become required if field "Responsibility #1" no longer says "Please enter Job Responsibility". 

I know that I need to leverage custom javascript placed within the validation tab of field "Responsibilty #1" but thus far I have not had any success. This seems rather straight forward but all the examples I have found online are from years in the past and I can't seem to get any of the examples to work properly.

Anyone have an idea? Thoughts? 

Thanks,
Cody Henslee

TOPICS
Create PDFs , General troubleshooting , How to , JavaScript

Views

608

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

Community Beginner , Apr 21, 2021 Apr 21, 2021

I found a work around by using a custom script on the calculation tab of the comment field.

var v = this.getField("Responsibility #1").value;

if (v=="Please enter Job Responsibility from Job Description."){event.target.required=false}else{event.target.required=true}

Votes

Translate

Translate
Community Beginner ,
Apr 21, 2021 Apr 21, 2021

Copy link to clipboard

Copied

Here is the current javascript I have put together but var role is returning "undefined" even though it is populated with "Please enter Job Responsibility"

var role = this.getField("Responsibility #1").value;
var comment = this.getField("R1 - Comments");

if (role!="Please enter Job Responsibility"){
this.getField(comment).mandatory = true;
}else{this.getField(comment).mandatory = false;
}

 

Votes

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

Copy link to clipboard

Copied

I found a work around by using a custom script on the calculation tab of the comment field.

var v = this.getField("Responsibility #1").value;

if (v=="Please enter Job Responsibility from Job Description."){event.target.required=false}else{event.target.required=true}

Votes

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 ,
Feb 03, 2022 Feb 03, 2022

Copy link to clipboard

Copied

Hi, I'm trying something similar but cannot make it works. 

I have a radio-button fieldA (YES/NO) and need to make mandatory the Field B only if Field A si selected NO. 

Could you help?

Thank you

regards

B

Votes

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 Expert ,
Feb 03, 2022 Feb 03, 2022

Copy link to clipboard

Copied

Generally the way to do this with a radio button is to put a MouseUp script on each of the buttons.

Use this on the "No" button.

 

this.getField("FieldB").required = true;

 

Put this script on the MouseUp for the "Yes" button.

 

this.getField("FieldB").required = false;

 

This methodology is very simple and does not take into account form reset. If reset is an issue, then you'll need to include a script for setting the required property on reset.  

Also, the required property only blocks form submission. So if you are not submitting the form, you'll need another methodolgy.

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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 ,
Feb 04, 2022 Feb 04, 2022

Copy link to clipboard

Copied

Thank you Tom. It works perfectly. 

Now, onw more twist. Have a fieldA with drop-down list to select options (white, blue, orange, red, yellow, brown, black). and a radio-button fieldB with two options. 

How can we make FieldB mandatory only if fieldA is black or brown or blue? 

 

thank you in advance!

B

 

Votes

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 Expert ,
Feb 07, 2022 Feb 07, 2022

Copy link to clipboard

Copied

LATEST

The easiest solution for using a single dropdown to set a property on another field is to use a validation script on the dropdown. 

So, put this script into a custom validation script on "fieldA": https://www.pdfscripting.com/public/Form-Data-Validation.cfm

 

 

this.getField("fieldB").required = ((event.value == "black") || (event.value == "brown") || (event.value == "blue"));

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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