Copy link to clipboard
Copied
I would like to make 5 fields required to be filled in but only if a different field is filled in. For example
if "Text5" has a value
then "Text18" "Text31" "Text32" "Text57" "Text70" are required
it also needs to include
if a value is input into "Text5", then removed or deleted
then "Text18" "Text31" "Text32" "Text57" "Text70" are no longer required
The removal function is because I have a print button checking for required fields, so it has to turn back off too for that to work.
Thanks
Copy link to clipboard
Copied
Put this on the Validate script for Text5
var bRequired = event.value != event.target.defaultValue;
this.getField("Text18").required = bRequired;
...etc for the rest of the fields
Copy link to clipboard
Copied
Put this on the Validate script for Text5
var bRequired = event.value != event.target.defaultValue;
this.getField("Text18").required = bRequired;
...etc for the rest of the fields
Copy link to clipboard
Copied
Thank you SO much! I was just searching the community for answers because I had a similar issue. This is so easy!!!!
Copy link to clipboard
Copied
You can use the "if( [some logical statement] ) else " statement of JavaScript to test if "Text5" has a none null string value or if a number is not zero or a null string. If the result of the test is true then you use a block of code to set fields "Text18" "Text31" "Text32" "Text57" "Text70" to being required. If not true then set them to not required or the "required" property to false. I would make that an on "Blur" or exit action.
Copy link to clipboard
Copied
Guys thanks for the help, I should have clarified better to begin with but I understand very little Java script writing.
Can you break it down Barney style for me?
I've been copying and pasting from forums but don't have a good grasp writing the code yet.
Copy link to clipboard
Copied
I found part of the answer and it works, but I need it to turn off the required field if the value of "Text5" goes back to being empty.
var q = this.getField("Text5");
var d = this.getField("Text18");
var p = this.getField("Text57");
var b = this.getField("Text70");
var g = this.getField("Text31");
var t = this.getField("Text32");
console.println(q.value);
d.required = false;
p.required = false;
b.required = false;
g.required = false;
t.required = false;
if (this.getField("Text5") != null);
{
d.required = true;
p.required = true;
b.required = true;
g.required = true;
t.required = true;
}
Copy link to clipboard
Copied
Almost got it but it's backwards from the way I want. Can anyone help?
var v = (event.value==null || event.value=="");
var d = this.getField("Text18");
var p = this.getField("Text57");
var b = this.getField("Text70");
var g = this.getField("Text31");
var t = this.getField("Text32");
d.required = v;
p.required = v;
b.required = v;
g.required = v;
t.required = v;
Copy link to clipboard
Copied
So what about the code I provided didn't work for you? The answer is already there.
Copy link to clipboard
Copied
I must have made a mistake on it yesterday. I tried it again after your response and it worked just like it should. Thanks for the help