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

How to toggle a Text Field between required and not required when a check box is checked/unchecked?

New Here ,
Aug 13, 2020 Aug 13, 2020

Hello,

So I'm new to this.  I have made it so a text field is required when a specific check box is checked.  My issue is that when you uncheck the box, the text field remains required.  I have researched and researched this, and I simply can't figure it out.  I used the code below to make the text field requried when the box is checked.  If anyone can help, that'd be fantastic!!!!!

 

var f = this.getField("Medicaid on")
f.required=true;
f.display = display.visible;

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , How to , PDF forms
1.8K
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 ,
Aug 13, 2020 Aug 13, 2020

You can also run the same script as a mouse-up action from the checkbox field object:

 

 

var v = this.getField("myTextField");
var f= event.target;
if (f.value !="Off") {
v.required = true;
} else { 
v.required = false;
}

 

 

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 ,
Aug 13, 2020 Aug 13, 2020

+++EDITED REPLY

 

You mentioned asked about making a field required or not required based on the check or unchecked state of the checkbox.

Your script,  however, is to hide or unhide the text field.

 

You can use the same script for that.

 

var v = this.getField("Text67");
var f= event.target;
if (f.value !="Off") {
v.display= display.visible;
} else { 
v.display = display.hidden;
}

 

You can use something like this as the custom calculation script of the textfield where the field properties changes will take place:

 

 

 

var v = this.getField("myCheckBox");
var f= event.target;
if (v.value !="Off") {
f.required = true;
} else { 
f.required = false;
}

 

 

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 ,
Aug 13, 2020 Aug 13, 2020

You can also run the same script as a mouse-up action from the checkbox field object:

 

 

var v = this.getField("myTextField");
var f= event.target;
if (f.value !="Off") {
v.required = true;
} else { 
v.required = false;
}

 

 

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 ,
Aug 13, 2020 Aug 13, 2020
LATEST

Or simply:

this.getField("myTextField").required = (event.target.value!="Off");

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