Copy link to clipboard
Copied
Hi there!
I'm moderately savvy with using calculation and validation scripts, but this one is stumping me! What I am trying to do is what I lovingly call "user-proof" a 401(k) enrollment form, to prevent employees from entering information that contradicts their selections, which will require rework for our HR team, because they'll have to follow up with employees to understand what they really meant to enter. I think this will be easiest to explain if you have a visual of the form first:
So what I'm trying to do is require the user to select one of four radio buttons (group: Deferral Type -- options, in order: Pre-Tax Only, Post-Tax Only, Pre-Tax & Post-Tax, None). If they select one radio button, they must fill out one of two of the associated fields -- % or $ amount. They cannot fill out both. Example: employee wants to make Pre-Tax contributions, they select Pre-Tax Only button, and they must fill out either Pre-Tax % or Pre-Tax $, but if they fill out Pre-Tax %, they cannot fill out Pre-Tax $. They will also be blocked from filling out the fields associated with other radio buttons (e.g., Post-Tax %, Both Pre-Tax $, etc.).
The "Pre-Tax & Post-Tax" option might be additionally complicated, because they have to fill out two of the four fields, though I think it might not be as complicated as I'm making it in my head.
Any ideas on how to achieve this very specific request are greatly appreciated. If I can't make this work, I'll just make the fields optional and hope employees will know to fill out one field or the other, not both, but we'll see!
Copy link to clipboard
Copied
I changed the field names because the $ and % characters can cause issues. Enter this custom validation script in the Pre-Tax Percent field:
if(event.value && this.getField("Pre-Tax Dollar").value)
{
app.alert("Chose either Pre-Tax Percent, or Pre-Tax Dollar, but not both.",1);
event.value="";
}
Enter this script in the Pre-Tax Dollar Field:
if(event.value && this.getField("Pre-Tax Percent").value)
{
app.alert("Chose either Pre-Tax Percent, or Pre-Tax Dollar, but not both.",1);
event.value="";
}
The user will not be able to enter a value in one if the other already has a value, until they clear the value in the corresponding field.
Copy link to clipboard
Copied
Use this as custom calculation script of one of the text fields,
once one of the fields is filled, others will become read only:
var fields = ["Pre-Tax %","Pre-Tax $","Post-Tax %","Post-Tax $","Both - Pre-Tax %","Both - Pre-Tax $","Both - Post-Tax %","Both - Post-Tax $"];
var count = 0;
for(var i=0; i<fields.length; i++){
var f = this.getField(fields[i]);
if(f.valueAsString !== ""){
count = 1;
break;}}
for(var j=0; j<fields.length; j++){
var c = this.getField(fields[j]);
if(count == 1 && c.valueAsString == ""){
c.readonly = true;}
else
c.readonly = false;}