Validate Required Fields on the Current PDF Page in Adobe Acrobat
Question details
Validate only the required PDF form fields on the page containing the clicked button before saving.
- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A multipage PDF form has a validation button on each page.
- Observed behavior
- The existing button script checks required fields throughout the document instead of limiting validation to the current page.
Open the PDF in Adobe Acrobat and check that the fields to validate have the Required property enabled. Use a uniquely named button on each page so its page property identifies one page.
Filter Required Fields by the Button's Page
Use this approach to validate required text fields, checkboxes, radio buttons, and choice fields on the page containing the clicked button.
The script compares each required field's page property with the button's page. A field with widgets on multiple pages is included if one of its widgets is on the button's page.
This example checks whether supported fields are empty; it does not validate field formats or signatures. It also does not save automatically or prevent a user from saving through another command.
In Adobe Acrobat, open Prepare a Form, then right-click the page's button and select Properties.
On the Actions tab, choose Mouse Up as the trigger and Run a JavaScript as the action, then select Add.
Enter this script in the JavaScript editor: (function () { var currentPage = event.target.page; if (typeof currentPage !== 'number') { app.alert('Use a uniquely named button on each page.'); return; } var missing = []; for (var i = 0; i < this.numFields; i++) { var f = this.getField(this.getNthFieldName(i)); if (!f || !f.required) continue; var pages = f.page; var onPage = typeof pages === 'number' ? pages === currentPage : false; if (pages && typeof pages !== 'number') { for (var j = 0; j < pages.length; j++) { if (pages[j] === currentPage) onPage = true; } } if (!onPage) continue; if (f.type !== 'text' && f.type !== 'checkbox' && f.type !== 'radiobutton' && f.type !== 'combobox' && f.type !== 'listbox') continue; var value = f.valueAsString; if (value === '' || value === 'Off' || /^\s*$/.test(value)) missing.push(f.name); } if (missing.length) { app.alert('Complete these required fields before saving:\n' + missing.join('\n')); } else { app.alert('Required fields on this page are complete. You can save the form.'); } }).call(this);
Close the properties dialog, exit form editing, and click the button with a required field empty. Fill the field and click again; then repeat on the other pages before using File > Save.

Work with PDFs 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 makes it easy to move existing documents into WPS, but it does not fix Acrobat's form-validation script or guarantee that PDF JavaScript will run.

Frequently Asked Questions
How does the script identify the current page?
In the button's Mouse Up JavaScript action, event.target.page identifies the page associated with the clicked button. Use a unique button name on each page so the property resolves to a single page.
Can I validate a specific list of fields instead?
Yes. In each button's JavaScript action, define an array of field names for that page and use this.getField(name) to check each field directly. Update the array whenever you add or rename a field.
Why does a field appear on more than one page?
A PDF field can have multiple widgets on different pages. Its page property may therefore contain multiple page numbers, and widgets with the same field name share a value.
Does the validation button stop all saves if a field is empty?
No. The example only displays a message when the button is clicked; it does not block File > Save or other save commands.




