Toggle an Adobe Acrobat Form Field Between Required and Optional
Question details
Make a PDF comment field required when Yes is selected and optional when No is selected.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form uses a checkbox selection to control whether a user must enter a comment.
- Observed behavior
- The comment field becomes required when Yes is selected but remains required after the user selects No.
Open the PDF in Acrobat and identify the exact name and export value of the Yes checkbox in Prepare Form. Check for existing scripts that also set the comment field's required property, as they may conflict with the calculation.
Recalculate the comment field's required state
Use a custom calculation script to set the comment field as required when the Yes checkbox has the specified export value and optional otherwise.
Open the PDF in Adobe Acrobat and select Prepare Form from the tools.
Open the Yes checkbox's Properties and check its field name on the General tab and its export value on the Options tab.
Open the comment field's Properties, select the Calculate tab, choose Custom calculation script, and click Edit.
Enter event.target.required = this.getField("Yes1").valueAsString == "Yes_3"; and replace Yes1 and Yes_3 with the checkbox's actual field name and export value. Save the script and close Properties.
Close form editing, select Yes, and check that the comment field is required. Then select No and verify that the comment field is optional. Save the PDF after testing.

Work with PDF and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDF and Office files. Its format compatibility can make moving everyday documents to WPS easier, but it does not fix Acrobat form JavaScript.

Frequently Asked Questions
Where do I find the checkbox's export value?
In Acrobat, open Prepare Form, open the checkbox's Properties, and select the Options tab. Use the listed export value in the calculation script.
Why does the comment field remain required after I select No?
The existing script may set the field to required without setting it back to optional. A custom calculation on the comment field assigns the required property based on the checkbox's current value.
What should I change in the example script?
Replace Yes1 with the exact checkbox field name and Yes_3 with its export value. You can check both in the checkbox's Properties in Prepare Form.
Will this script work in every PDF viewer?
Not necessarily. The solution relies on Acrobat form JavaScript, which other PDF viewers may not support. Test the form in the viewer your users will use.




