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
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}
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;
}
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}
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
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.
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
Copy link to clipboard
Copied
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"));