Copy link to clipboard
Copied
I have a dropdown field (Type_Study) with 10 options, 4 of which begin with the word "Sensitization."
I have 2 fields which only need to be visible if:
a) the choice from the dropdown includes "Sensitization" or "all", and
b) if a different dropdown (Storage1) is not equal to "Select Option"
I believe I would need to add a custom calculation script to the fields to be visible or hidden and I have the script to make the field visible based on b) but I do not know how to script a) and combine it with b).
So far, I have:
if (this.getField("Storage1").value != "Select Option") {
event.target.display = display.visible;
} else {
event.target.display = display.hidden;
}
Any help would be appreciated.
Thanks,
Jane
No need, it's possible to check if one value contains another, it's just a bit trickier.
Try this code:
...var v1 = this.getField("Type_Study").valueAsString;
var v2 = this.getField("Storage1").valueAsString;
if ((/All 3 Assays/.test(v1) || /DPRA/.test(v1) || /KeratinoSens/.test(v1)) && v2!="Select Option") {
this.getField("Field1").display = display.visible;
this.getField("Field2").display = display.visible;
} else {
this.getField("Field1").display = display.hidden;
this.getField("Fi
Copy link to clipboard
Copied
Because you want to do it based on the value of multiple fields, it's a bit more complicated.
You can use this code as the custom calculation script of a (hidden) text field to achieve it:
var v1 = this.getField("Sensitization").valueAsString;
var v2 = this.getField("Storage1").valueAsString;
if ((/Sensitization/.test(v1) || /all/.test(v1)) && v2!="Select Option") {
this.getField("Field1").display = display.visible;
this.getField("Field2").display = display.visible;
} else {
this.getField("Field1").display = display.hidden;
this.getField("Field2").display = display.hidden;
}
You'll need to enter the actual field names in lines 4, 5, 7 and 8, of course.
Edit: code fixed
Copy link to clipboard
Copied
There was a mistake in the code above. I fixed it now.
Copy link to clipboard
Copied
Thank you for this but I am still not able to make it work. I realize that I was not clear enough in the parameters and conditions, nor am I sure which field to attach the script to, so I would like to start over...
1) Would I build the custom calculation script in the field that is currently hidden but needs to be visible when the parameters/conditions are met?
and
2) Assuming 1 is correct, here are my parameters, which are identical for both of the fields:
Thanks for your help try67!
Jane
Copy link to clipboard
Copied
1) You can put it under one of those fields, yes.
2) You keep writing "contains". Do you mean "equals"? The two require quite different approaches, and the latter is much simpler.
Copy link to clipboard
Copied
OK, thanks.
I was hoping not to have to spell out the full value... hence my use of contains but if equals is simpler, I can write the full text of the field. Let's do that and I will replace my text in " " with full text.
Many thanks.
Jane
Copy link to clipboard
Copied
No need, it's possible to check if one value contains another, it's just a bit trickier.
Try this code:
var v1 = this.getField("Type_Study").valueAsString;
var v2 = this.getField("Storage1").valueAsString;
if ((/All 3 Assays/.test(v1) || /DPRA/.test(v1) || /KeratinoSens/.test(v1)) && v2!="Select Option") {
this.getField("Field1").display = display.visible;
this.getField("Field2").display = display.visible;
} else {
this.getField("Field1").display = display.hidden;
this.getField("Field2").display = display.hidden;
}
(I'm still not sure what are the names of the fields you want to show/hide...)
Copy link to clipboard
Copied
Great! Thank you.