PDF Editing Issues

How to Validate Only Visible Required Fields in an Acrobat PDF Form

Chanuka GeekiyanageChanuka Geekiyanage Nov 3, 2026 869 views

Question details

The user needs to validate manual-entry fields in a PDF form using JavaScript, ensuring that only visible required fields are checked while hidden ones are ignored.

How to Validate Only Visible Required Fields in an Acrobat PDF Form
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating or editing an interactive PDF form where certain required fields are dynamically hidden based on calculations, and need a validation script before form submission.
Observed behavior
Validating all required fields prevents form submission if hidden fields are empty. The goal state is to explicitly reference and check the display state of each field using JavaScript so hidden fields bypass validation.
Before you start

Ensure you have access to the JavaScript editor in your PDF form builder and make a note of the exact system names for all the form fields you intend to validate.

Solution 1Recommended

Use Explicit Field Referencing in JavaScript

Write a custom JavaScript validation script that explicitly checks if a specific field is both empty and visible before triggering a validation alert.

When dealing with dynamic PDF forms, standard required field settings apply regardless of visibility. To bypass this, you must handle the validation through JavaScript manually on the submission button.

A common mistake is using incomplete syntax when checking the display state. You must reference the exact field object for both the value check and the visibility check.

1
Access Form Editing Mode

Open your PDF form in Adobe Acrobat and enter the 'Prepare Form' mode to view all available form fields.

2
Open Action Properties

Right-click the Submit button (or the specific document action you are using for validation) and select 'Properties'.

3
Add a JavaScript Action

Navigate to the 'Actions' tab, select 'Run a JavaScript' from the 'Select Action' dropdown menu, and click 'Add'.

4
Input the Validation Code

Enter the explicit validation code. For example: if (this.getField("MANUAL1").valueAsString == "" && this.getField("MANUAL1").display == display.visible) { app.alert("You must first fill in the required fields."); }

5
Save and Test

Click 'OK' to save the script, exit form editing mode, and test your form to ensure the alert only triggers when 'MANUAL1' is both visible and left empty.

Use Explicit Field Referencing in JavaScript
Syntax Warning: Do not use the incorrect shorthand syntax like `.display == display.visible`. You must explicitly call `this.getField("FIELD_NAME").display == display.visible` for the script to execute successfully.
Edit PDF Forms Easily

Create and Manage PDF Forms with WPS PDF

WPS Office includes a robust PDF editor that allows you to easily create, edit, and manage interactive PDF forms. You can design fields, set required properties, and handle form data seamlessly without complex coding.

  1. 1. Open WPS PDF: Launch WPS Office and open your PDF document using the built-in WPS PDF tool.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to reveal the comprehensive suite of form editing tools.
  3. 3. Edit Form Fields: Select the text field, checkbox, or button you want to edit. Double-click it to open the properties panel where you can define visibility and required parameters.
  4. 4. Save and Distribute: Save your edited PDF document. Your interactive form is now ready to be distributed and filled out by users.
Easily create interactive PDF forms with text fields, checkboxes, and buttons.Fully compatible with standard PDF formats and Adobe Acrobat forms.Lightweight, fast, and features an intuitive user interface.Comprehensive tools for document security, electronic signatures, and PDF conversion.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my JavaScript validation fail on hidden PDF fields?

If your script doesn't explicitly check the display property (e.g., using `this.getField('FieldName').display == display.visible`), the application will attempt to validate the field even when it is hidden, triggering unwanted validation errors.

How do I find the exact name of a form field in Acrobat?

Enter the 'Prepare Form' mode. The system names of all form fields will be displayed directly over the fields on the document. You can double-click a field to view or copy its exact name from the Properties dialog.

Can I validate multiple visible fields with one script?

Yes, you can chain multiple `if` conditions together or use a JavaScript loop to iterate through an array of field names, checking the visibility and value of each specific field before allowing submission.

What is the correct JavaScript syntax for checking field visibility?

The correct syntax is explicitly defining the field: `this.getField('FIELD_NAME').display == display.visible`. Relying on relative paths or omitting the explicit `getField` call will cause the script to fail.