Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Can't get radio buttons or checkboxes to update live via validation in another field?

Explorer ,
May 24, 2023 May 24, 2023

I'm working on customizing a test that uses a lot of totals that funnel into a final percentage. The totals are sums of dropdowns that add between 0 and 1 point to the score (plus there is a text field for deductions at the end). Eventually there is a final total and a percentage. The percentage uses both the Calculate tab and the Validate tab.

 

The calculation works great and is this:

var a = this.getField("Numerator").value;
var b = this.getField("Denominator").value;
if (b != "" && b != 0) {
    event.value = a/b;
}
else {
    event.value = "";
}

 

The validation works for our general use cases, and turns on/off two radio buttons for Pass or Fail:

var percentage = event.value;
 
if (percentage >= 0.90) {
    this.getField("pass").value ="Choice1";
    this.getField("fail").value ="None";
} else if (percentage < 0.90) {
    this.getField("fail").value ="Choice1";
    this.getField("pass").value ="None";
}

 

However, I'm trying to add automatic fail functionality that works off a set of radio buttons (so even if the score is over 90%, having one of these radio buttons selected will fail the test). I previously tried doing this with checkboxes as well. If I put the code directly into the radio or checkboxes, I can mostly get the live update to work. Ideally I'd like to have it all in one spot though, in the validation field mentioned above.

 

To do this, I tried the following:

var percentage = event.value;
var errors = [this.getField("Option01"),
              this.getField("Option02"),
              this.getField("Option03"),
              this.getField("Option04"),
              this.getField("Option05"),
              this.getField("Option06")];
var autoFail = false;

for (var i = 0; i < errors.length; i++) {
    if (errors[i].value == "NC" || errors[i].value == "MT") {
        autoFail = true;
    }
}

if (autoFail) {
    this.getField("overfail").value ="Choice1";
    this.getField("overpass").value ="None";
} else {
    if (percentage >= 0.90) {
		this.getField("pass").value ="Choice1";
		this.getField("fail").value ="None";
    } else if (percentage < 0.90) {
		this.getField("fail").value ="Choice1";
		this.getField("pass").value ="None";
    }
}

 

..Which sort of works, but nothing actually happens after you change the radio button. The change doesn't reflect in the Pass/Fail radio buttons until I update a dropdown or field as well, which changes the final total. I'm wondering if this is because those are all connected throughout the calculations, whereas the radio buttons only show up in the process at the very end in that one validate tab? I'm a bit of a javascript notice and sometimes unsure of how acrobat decides things in calculations. Any advice would be helpful!

 

Screen Shot 2023-05-24 at 1.30.27 PM.png

TOPICS
General troubleshooting , JavaScript , PDF
894
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
May 24, 2023 May 24, 2023

Use the Calculate event.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2023 May 24, 2023

Where did you place this code, exactly?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 24, 2023 May 24, 2023

I placed the code into the last field in the chain of calculations (in the image as the 100.00% next to Pass and Fail. More specifically into the Validate tab.

 

I found a solution that works, but it involves placing code in every single radio button, which I was hoping I could avoid if possible.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2023 May 24, 2023

Use the Calculate event.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 24, 2023 May 24, 2023

Thanks, I moved all the code to the calculate tab and after some fiddling, have it working. (The code was separated into the two before I started working with the documents, so I'm not very familiar with what the difference is between putting code into Calculate and into Validate.) 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2023 May 25, 2023
LATEST

The main difference is that the Calculate event fires after the value of any field is changed, while the Validate event only fires after that same field's value is changed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines