Conditionally required field
Here's what I'm trying to do. I have a series of 6 sets of fields with 2 fields in each series (Name & Age). Name is a single line text element and Age is currently a lookup into a table containing valid ages. So in other words I have Name1/Age1, Name2/Age2, Name3/Age3, Name4/Age4, Name5/Age5, Name6/Age6 for a total of 8 fields. I want to do some validation on submit such that name and age values have to be submitted in pairs. Meaning, if a user specifies a value for Name1 they must also specify a value for Age1 and vice versa... if they specify an Age, they must also provide a Name. However, if they don't provide values for both fields, that's fine as well. Any thoughts?
I tried writing a function to do the validation, but I get an error when calling it.
bool childcare.isChildAgeProvided(string childName, string childAge)
{
info "name:" + input.childName + " age:" + input.childAge + ";";
if (((input.childName != null) && (input.childAge != null)) && (((input.childName).length() > 0) && ((input.childAge).length() > 0)))
{
info 1;
return true;
}
else if (((input.childName).length() == 0) && ((input.childAge).length() == 0))
{
info 2;
return true;
}
return false;
}