I have a form with a dropdown input, so the options for that input are already set.
The problem is that the value of the input, despite being correct and it is within the accepted values of the schema I got the message that Provider must be one of [[object Set], [object Set]].
Most weird thing is that this problem is ocurring in production, but in localhost I don't get this validation error.
provider key from the schema:
provider: Joi.string().required().label('Provider').when('entitlementType', {
is: 'Offer',
then: Joi.string().valid(...providersForSubscriptions),
otherwise: Joi.string().valid(...providersForProducts),
}),
providersForSubscriptions array:
[
"RBL",
]
providersForProducts array:
[
"RBL",
"content-store",
"zencore",
"VIP"
]
As you can see is a quite simple validation, it will receive some provider value and will accept the value if it's within the valid arrays.
Loging the form in the browser.
console.log(entitlementType, provider, providersForProducts);
And this is the output:
So what's going on? If we check the context from the validation warning, the input value is zencore and zencore is considered as a valid value.
Any thoughts? Should I try refactoring the schema? Why this is prod only?
From your schema:
provider: Joi.string().required().label('Provider').when('entitlementType', {
is: 'Offer',
then: Joi.string().valid(...providersForSubscriptions),
otherwise: Joi.string().valid(...providersForProducts),
}),
And your output, we can see that entitlementType is NOT offer. So that means
Joi.string().valid(...providersForProducts),
is being used for validation on this particular field.
We can also see the error Provider must be one of [[object Set], [object Set]] which means that Joi is checking against an array of sets.
That points us to providersForProducts as the culprit.
Why is it an array of sets? Who knows. Log that value to confirm and then work your way back to see why it's set as such.