PDF JavaScript - Make Field Required Based on Radio Button Selection

Viewed 24

I have a PDF document that I'm creating in Adobe Acrobat Pro, and I need to add some additional behaviour to it using JavaScript (which I don't know). This screenshot shows the issue: enter image description here There are two radio buttons in the middle two columns which are mutually exclusive - people filling in the form can either select Yes or No. For some of the questions if they select Yes, I would like to make the Details text field required.

I have gone to Prepare Form -> More -> All JavaScripts and added the following code to the bottom; again, I don't have a good handle on this, so my solution so far was to simply have an array of arrays of the names of the fields I want to check, and the names of the corresponding Details boxes. I loop through the fields and check if the value of the radio button group is "Yes", and set the required field to true if it is. (Yes and No are the names of the buttons if I open up the Radio button group on the right, but I don't know if they are strings or exactly how they are stored.) It doesn't complain, but it doesn't work, either, and allows a user to complete the form without asking for the Details box to be filled if the corresponding Yes button is ticked:

var requiredFields = new Array(1)
requiredFields[0] = ["Tuberculosis, asthma, bronchitis, or chest problems?", "Details 02"]
requiredFields[1] = ["Chest pain, heart condition or raised blood pressure?", "Details 03"]
requiredFields[2] = ["Rheumatism or arthritis?", "Details 04"]
requiredFields[3] = ["Blackouts, fits or attacks of dizziness?", "Details 05"]
requiredFields[4] = ["Bladder or kidney trouble?", "Details 06"]
requiredFields[5] = ["Dermatitis, skin issues, or Varicose veins?", "Details 07"]
reqiuredFields[6] = ["Depression, mental illness, or nervous breakdown?", "Details 08"]
reqiuredFields[7] = ["Any illness or medical condition, including defect of sight or hearing?If yes, please specify any special needs in the relation to your disability?", "Details 09"]
reqiuredFields[8] = ["Any other current or recent medical condition that prevented you from attending work on your normal duties or activities for more than one week during the past 12 months?", "Details 11"]
reqiuredFields[9] = ["Any past accidents or operations?", "Details 12"]

for (let i = 0; i < requiredFields.length; i++) {
    if this.getField(requiredFields[i][0]).value == "Yes" {
        this.getField(requiredFields[i][1]).required = true;
    }
}

I don't know if the button .value field is actually "Yes" or a boolean, or something else, but I have checked for both and neither fixes the issue. I think what I need is a check that runs when the button is actually clicked to identify which button was selected, and set required as appropriate. I found several threads about this that seemed more browser-specific, and I wasn't sure how to translate this to a PDF, or Adobe.

I need this for work, so any help would be greatly appreciated!

0 Answers
Related