How to Make Acrobat PDF Form Fields Read-Only After Required Fields Are Complete
Question details
The user wants to validate required PDF form fields using JavaScript and subsequently lock only the text fields to read-only before the form is submitted.

- Product
- Adobe Acrobat PDF
- Device & OS
- not provided
- Scenario
- Creating a custom submit action in a PDF form that enforces required data entry before permanently locking specific form elements.
- Observed behavior
- The current JavaScript routine locks all form fields indiscriminately before checking if required fields are filled, which prevents validation and incorrectly disables buttons or signatures.
Ensure you have access to a PDF editor that supports advanced JavaScript for forms, and always keep a backup copy of your original editable PDF file before testing new validation scripts.
Use JavaScript to Validate and Selectively Lock Text Fields
Create a two-step script that first loops through fields to verify required entries, and then runs a second loop to lock only elements classified as text fields.
When designing interactive PDF forms, indiscriminately locking all fields during submission can break the process by disabling functional buttons and signature boxes. To avoid this, your JavaScript must separate validation from the property-changing actions.
The script will first ensure that every field flagged as 'required' has a valid value. Only when all mandatory conditions are met will the code proceed to change the properties of text fields to read-only.
Launch your PDF form in Adobe Acrobat. Navigate to the 'Tools' menu and select 'Prepare Form' to enter editing mode.
Right-click your intended 'Submit' button on the document and choose 'Properties'. Go to the 'Actions' tab, select 'Run a JavaScript' from the 'Select Action' dropdown, and click 'Add'.
In the JavaScript editor, create a loop iterating through 'this.numFields'. For each field, check if 'this.getField(fname).required' is true and if its current value matches its 'defaultValue' or is empty. If an empty required field is found, trigger an 'app.alert' and return out of the function to halt submission.
Below the validation loop, create a second loop that executes only if validation passes. Check the field type using 'this.getField(fname).type === "text"'. If true, set 'this.getField(fname).readonly = true'.
Add the final line of code to execute the actual submission process using 'this.submitForm(...)' with your required parameters, then click 'OK' and save your PDF.

Edit and Manage PDF Forms Easily with WPS PDF
If you frequently work with interactive PDF forms and need a reliable, lightweight application, WPS Office provides an intuitive PDF tool to view, fill, and manage PDF forms effortlessly.
- 1. Open Your PDF Form: Launch WPS Office and open your interactive PDF form document.
- 2. Fill the Required Fields: Click directly on the highlighted form fields to enter your text, or check the necessary boxes.
- 3. Flatten the PDF: To quickly make all fields read-only and prevent further editing, go to 'Menu' > 'Print' and choose 'Print to PDF', or use the export functions to save a flattened version.

Frequently Asked Questions
Why shouldn't I lock all PDF fields upon submission?
Locking all fields indiscriminately will also disable functional elements like the Submit button itself or digital signature fields, preventing users from successfully completing the signing or submission process.
How do I check a field type using PDF JavaScript?
You can access a specific field's type property using the syntax 'this.getField("FieldName").type'. Common return values include 'text', 'button', 'checkbox', and 'signature'.
Can I make fields read-only without using JavaScript?
Yes, you can manually set an individual field to read-only by right-clicking it in Form Editing mode, selecting Properties, and checking the 'Read Only' box under the General tab. However, making it dynamic based on required field validation requires JavaScript.




