How to Show a PDF Form Alert Only When Required Fields Are Incomplete
Question details
Configure a PDF form to display a validation alert for an unanswered radio button only if another specific field (like a Name field) has been filled out.

- Product
- Device & OS
- not provided
- Scenario
- Setting up conditional validation for required fields before saving or printing a PDF form.
- Observed behavior
- The user wants the document to evaluate if the 'Name' field contains text and if the corresponding radio button is left blank before displaying a validation alert, allowing entirely blank forms to remain unaffected.
Before modifying form actions, ensure you are using a PDF editor that supports form field properties and document-level JavaScript execution.
Use JavaScript for Conditional Form Validation
Apply a custom script to the Document Will Save action to check if the text field is filled while the radio button remains unanswered.
Instead of checking the standard 'Required' box for a form field, which triggers warnings globally, you can use document-level JavaScript. This allows the PDF to evaluate multiple conditions before alerting the user.
Open your PDF document and enter the Form Editing mode to access the document-level JavaScript or action settings.
Navigate to the Document Properties and find the 'Document Will Save' action trigger.
Add a JavaScript action that evaluates the conditions. For example: `if (this.getField('Name').valueAsString !== '' && this.getField('RadioGroup').value === 'Off') { app.alert('Please select an option.'); this.getField('RadioGroup').setFocus(); }`.
Exit form editing mode. Test the PDF by saving it as a completely blank form, then test again by filling in only the Name field to ensure the alert triggers properly.

Create and Manage Smart PDF Forms with WPS Office
WPS Office provides advanced PDF editing tools, allowing you to easily add text fields, radio buttons, and custom validation rules to your interactive forms.
- 1. Open PDF in WPS Office: Launch WPS Office and open your PDF document. Navigate to the 'Form' tab on the top ribbon.
- 2. Add Form Controls: Click on 'Text Field' or 'Radio Button' to insert the required interactive elements into your document.
- 3. Configure Field Properties: Right-click the inserted field, select 'Properties', and navigate to the 'Actions' tab to define triggers or custom scripts.
- 4. Save the Interactive PDF: Click 'Save' to preserve the form fields and their interactive behaviors for easy distribution to users.

Frequently Asked Questions
Why does my PDF form alert trigger even when the form is empty?
This usually happens when a field is marked as 'Required' in its basic properties. Standard required fields trigger warnings on save or submit regardless of other fields. Uncheck the 'Required' box and use custom conditional scripts instead.
How do I find the exact name of a form field for my script?
Enter Form Editing mode, right-click the specific field, and select 'Properties'. The exact field name will be listed under the 'General' tab. Copy this exactly, as field names are case-sensitive.
Can I apply this conditional validation to the Print action as well?
Yes. You can attach the same conditional validation script to the 'Document Will Print' action in the document properties to ensure users complete required fields before printing the form.




