最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Specific JavaScript for a Fillable PDF - Stack Overflow

programmeradmin0浏览0评论

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
  • 2 You say you want to disable the button, but you never do so; you are setting it to readonly instead. – mykaf Commented Feb 12 at 20:20
  • @KJ, how does one set a button to "locked"? I'm not familiar with that attribute. Disabling it would prevent it from being clicked and prevent any of its actions from executing. I just tested a readonly button and it's still clickable and its events still fire and execute. – mykaf Commented Feb 12 at 22:13
Add a comment  | 

1 Answer 1

Reset to default 0

As 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
发布评论

评论列表(0)

  1. 暂无评论