I have a simple validation process set up but something isn’t right.
In coldbox.cfc I have -
validation = {
sharedConstraints = {
sharedUser = {
lname = {required=true},
addr1 = {required=true},
city = {required=true},
country = {required=true},
email = {required=true, type=“email”},
ofage = {required=true, type=“boolean”},
eligible = {required=true, type=“boolean”},
formeremp = {required=true, type=“boolean”}
},
loginForm = {
username = {required=true}, password = {required=true}
},
changePasswordForm = {
password = {required=true,min=6}, password2 = {required=true, sameAs=“password”, min=6}
}
}
};
I then have a form coming in for a new user. One of the radio button fields is “eligible”, which has two options - yes/no. Above it’s defined as required = true and type = boolean.
The handler does the following -
<cfset prc.validationResults = validateModel( target=rc, constraints=“sharedUser” ) />
If the field “eligible” is not passed in (neither radio button checked) I would expect it would get reported back as one of my validation errors. Instead I get the following -
Application Execution ExceptionError Type: GenericObject.InvalidKey : [N/A]
Error Messages: The key requested ‘ELIGIBLE’ does not exist in the collection
I read thru the docs again and I see that "required’ means “Whether the property must have a non-null value”. So, for radio buttons where the property doesn’t exist at all if nothing checked, what is the recommended way to treat these?
Thank you!
Irv