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

Conditional Formatting for multiple checkboxes, making a text field become required

Explorer ,
Nov 25, 2020 Nov 25, 2020

I'm trying to make a form where if any one of 6 checkboxes are not checked, it will make a specified text field required. What I have so far isn't working, and I tried building a provided off of a formula from my previous post. Below is what I've tried using with no success (most likely went way off course here), can someone maybe explain to me why it isn't working, and help me get a script that will work?? Thanks in advance!!

var r1 = this.getField("CB1").valueAsString;
var r2 = this.getField("CB2").valueAsString;
var r3 = this.getField("CB3").valueAsString;
var r4 = this.getField("CB4").valueAsString;
var r5 = this.getField("CB5").valueAsString;
var r6 = this.getField("CB6").valueAsString;
var r7 = this.getField("Text Field");

if (event.r1 != "Off" && event.r2 != "Off" && event.r3 != "Off" && event.r4 != "Off" && event.r5 != "Off" && event.r6 != "Off") {
r7.required = true
} else {
r7.required = false
}

 

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , How to , PDF forms
1.5K
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
Explorer ,
Nov 26, 2020 Nov 26, 2020
LATEST

The original code with the CORRECTIONS..... jumped the gun and got too excited!

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 ,
Nov 25, 2020 Nov 25, 2020

Remove the event. before r1, r2, ...

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 ,
Nov 25, 2020 Nov 25, 2020

Remove all "event." text. != means it's not OFF, in other words it's ON, so
if you want text field to be required while checkboxes are not checked
replace true with false and false with true, you can also add semicolon after false and true.
Put code in text field as "Custom Calculation Script".

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 ,
Nov 26, 2020 Nov 26, 2020

So I made the changes you both said, and then could only place into custom calculation script for the text field as you said... tested and still nothing came of it. The variables are included in the script, I just left them out to save space in showing you what I have for the "if - else" script now.

 

if (r1 != "Off" && r2 != "Off" && r3 != "Off" && r4 != "Off" && r5 != "Off" && r6 != "Off") {
r7.required = false
} else {
r7.required = true
}

 

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 ,
Nov 26, 2020 Nov 26, 2020

It's actually not even allowing it to stay in the custom calculation script, that's why it's not working. As soon as I click ok to submit it, it immediately changes back to "Value is not calculated."

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 ,
Nov 26, 2020 Nov 26, 2020

That should work, it must be something else in your file, try share your file with us or

see if this code works for you:

var check = 0;
for (var i=1; i<=6; i++) {
if (this.getField("CB"+i).valueAsString != "Off")check++}
event.target.required = check == 6 ? false : true;

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 ,
Nov 26, 2020 Nov 26, 2020

Annotation 2020-11-26 150453.png

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 ,
Nov 26, 2020 Nov 26, 2020

Hopefully that clarifies a little more as to what I'm trying to do.

I have no issues with getting the respective remarks for Check 'X', and Check 'Y'... it's just the r1...r6 to remarks that's giving me trouble.

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 ,
Nov 26, 2020 Nov 26, 2020

Soooooo I resolved the problem!!

 

You were right. what I was doing was correct... I just ended up taking the original code and amending it onto the already existing Mouse Up: Javascript script, separating it with proper {} marks, and verifying all information was accurate. Once I did that and tested it, everything worked!!

In the end it ended up making a 4 long unique scripts (one for r1, r2, r3 and r4, and then r5 and r6), and a 5th short script (base script in original post for "Remarks" as identified in the screenshot provided).

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 ,
Nov 26, 2020 Nov 26, 2020
LATEST

The original code with the CORRECTIONS..... jumped the gun and got too excited!

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