Copy link to clipboard
Copied
I am really banging my head against a wall and believe I have exhausted every possible search that I can. To paint a picture:
I am able to calculate the total of the checkboxes in a separate hidden field. If the value in this field is EQUAL to the total number of rows of checkboxes (in this case 8), I would like the "Checked" checkbox on the second mentioned page to be automatically checked. If the total value in this field is GREATER than 8, I would like the "Repaired" checkbox checked on the second mentioned page.
Is this possible to complete in 1 stage/field or do I need to first calculate the value of all the checkboxes on the first page and export to a field and then dynamically set another field equal to my export field and then dictate which checkbox should be checked on the second page? I know very confusing and can provide illustration of what I am trying to accomplish if necessary. Thank you to all who digest this and can offer support!!
Copy link to clipboard
Copied
That is a clever solution, but it does have a major fault. if half the repaired boxes were checked the sum equals the same if all checked boxes are checked.
It is more direct and simple to just loop over all checkbox groups and detect the required conditions.
Lets say all the check list groups are named like this.
"Checklist.row1", "Checklist.row2", etc.
Then this code will set the result checkboxes based on the conditions you've stated above,
the Checked checkbox is named "Checked" and the Repaired checkbox is named "Repaired", and the export values of the result checkboxes are "Yes"
var aFldList = this.getField("Checklist").getArray();
this.getField("Checked").value = aFldList.every(a=>a.value == 1)?"Yes":"Off";
this.getField("Repaired").value = aFldList.some(a=>a.value == 2)?"Yes":"Off";
The Array.every() function returns true if all elements of the array meet the test and the Array.some() function returns true if any element of the array meets the test.
Copy link to clipboard
Copied
That is a clever solution, but it does have a major fault. if half the repaired boxes were checked the sum equals the same if all checked boxes are checked.
It is more direct and simple to just loop over all checkbox groups and detect the required conditions.
Lets say all the check list groups are named like this.
"Checklist.row1", "Checklist.row2", etc.
Then this code will set the result checkboxes based on the conditions you've stated above,
the Checked checkbox is named "Checked" and the Repaired checkbox is named "Repaired", and the export values of the result checkboxes are "Yes"
var aFldList = this.getField("Checklist").getArray();
this.getField("Checked").value = aFldList.every(a=>a.value == 1)?"Yes":"Off";
this.getField("Repaired").value = aFldList.some(a=>a.value == 2)?"Yes":"Off";
The Array.every() function returns true if all elements of the array meet the test and the Array.some() function returns true if any element of the array meets the test.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
My apologies Thom, I didn't see the rest of your explanation and sample code. I will try and report back, have a great evening!
Copy link to clipboard
Copied
Well, I suppose summing could work if you used prime numbers so the summs are unique. But the script I provided in the previous post is much better. Don't over complicate things. Simple direct solutions are best.
The "." in the name is a way to group a set of form fields, so that all of the fields in a group can be acquired in a single line of code.
Copy link to clipboard
Copied
Hello Thom, that suggestion regarding the checkbox arrays that you recommended did the trick. I have one more question. Is there an action trigger besides "Mouse Enter" or "Mouse Exit" that I can use that will automatically change the checkboxes on my page second page? The checkboxes will not update until I hover over both. I was hoping to fill out the checklist in its entirety and not really have to review the second form at all. Thank you again for any suggestions you can offer!
Copy link to clipboard
Copied
The calculation scripts are triggered any time any field changes, so the calculation on the hidden field you're already using is perfect. This is where the script I provided should be. The script only needs to be put in one place to handle all checkbox changes.
If there is some other action you want to trigger on a checkbox change then yes, it is possible to add for example, a validation script to a checkbox. But this can only be done with another script.
See this article:
https://www.pdfscripting.com/public/Editing-Fields-Properties.cfm#JScript
And this one for more general form scripting info
https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm
Copy link to clipboard
Copied
@Thom Parkerwhat exactly does (a=>a.value == 1) do, I don't see 'a' declared?
Copy link to clipboard
Copied
That's an arrow function. It's a core JS feature. (the a is declared implicitly by it's use)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more