I have made a fillable form in Adobe Acrobat DC Pro with several field scripts to activate and deactivate related fields where applicable. One part is stumping me [total novice btw].
I created a button that runs a script to open the print menu, however, I want to set that same button to be deactivated (not hidden) until six specific required fields are filled in; five text fields and one date drop down. .
I have tried several ChatGPT generated options without luck. Scripts on the button, scripts on the required fields, scripts on both, document scripts...nada. Any insight would be greatly appreciated
function checkFields() {
var fields = \["TextField1", "TextField2", "Dropdown1"\]; // List of required fields
var button = this.getField("SubmitButton"); // The button to enable/disable
var allFilled = true; // Flag to track if all fields are filled
// Loop through each required field
for (var i = 0; i \< fields.length; i++) {
var field = this.getField(fields\[i\]);
// Check if the field is empty or not filled
if (!field.value || field.value.trim() === "") {
allFilled = false; // Set to false if any field is empty
break;
}
}
// Enable or disable the button based on whether all fields are filled
button.readonly = !allFilled; // Disable the button if fields are not filled
}
// Attach the checkFields function to required fields
var fieldsToMonitor = \["TextField1", "TextField2", "Dropdown1"\];
for (var i = 0; i \< fieldsToMonitor.length; i++) {
this.getField(fieldsToMonitor\[i\]).setAction("OnBlur", "checkFields();");
}
// Run the check on form load to disable the button initially
checkFields();
I have made a fillable form in Adobe Acrobat DC Pro with several field scripts to activate and deactivate related fields where applicable. One part is stumping me [total novice btw].
I created a button that runs a script to open the print menu, however, I want to set that same button to be deactivated (not hidden) until six specific required fields are filled in; five text fields and one date drop down. .
I have tried several ChatGPT generated options without luck. Scripts on the button, scripts on the required fields, scripts on both, document scripts...nada. Any insight would be greatly appreciated
function checkFields() {
var fields = \["TextField1", "TextField2", "Dropdown1"\]; // List of required fields
var button = this.getField("SubmitButton"); // The button to enable/disable
var allFilled = true; // Flag to track if all fields are filled
// Loop through each required field
for (var i = 0; i \< fields.length; i++) {
var field = this.getField(fields\[i\]);
// Check if the field is empty or not filled
if (!field.value || field.value.trim() === "") {
allFilled = false; // Set to false if any field is empty
break;
}
}
// Enable or disable the button based on whether all fields are filled
button.readonly = !allFilled; // Disable the button if fields are not filled
}
// Attach the checkFields function to required fields
var fieldsToMonitor = \["TextField1", "TextField2", "Dropdown1"\];
for (var i = 0; i \< fieldsToMonitor.length; i++) {
this.getField(fieldsToMonitor\[i\]).setAction("OnBlur", "checkFields();");
}
// Run the check on form load to disable the button initially
checkFields();
Share
Improve this question
edited Feb 12 at 23:22
Mister Jojo
22.6k6 gold badges25 silver badges44 bronze badges
asked Feb 12 at 20:13
Chris OwenChris Owen
11 bronze badge
2
|
1 Answer
Reset to default 0As I understood you want to disable button. but you currently set it as readonly, not disabled
button.readonly = !allFilled
change this to
button.disabled = !allFilled
readonly
instead. – mykaf Commented Feb 12 at 20:20