-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Imagine the following schema:
var schema = {
name : Joi.string().required(),
roles : Joi.array().items(Joi.string().valid('admin', 'moderator')),
gender : Joi.array().items(Joi.string().valid('male', 'female'))
};
Image the following examples:
Example 1
var data = {
name: 'test',
roles: ['admin'],
gender: ['male']
};
- Observation: This example validates to
true(what is expected)
Example 2
var data = {
name: '',
roles: ['admin'],
gender: ['male']
};
This example validates to false with the error:
[1] "name" is not allowed to be empty
- Observation: Here I know, that the field with the name
"name"throws the error. (what is expected)
Example 3
var data = {
name: 'test',
roles: ['waste'],
gender: ['male']
};
This example validates to false with the error:
[1] "0" must be one of [admin, moderator]
- Observation: Here I know, that the field with the name
"0"throws the error. - Issue: Here, I expect
rolesas the name of the field, with an hint to the incorrect index[0]
Example 4
var data = {
name: 'asd',
roles: ['admin', 'waste'],
gender: ['male']
};
This example validates to false with the error:
[1] "1" must be one of [admin, moderator]
- Observation: Here I know, that the field with the name
"1"throws the error. - Issue: Here, I expect
rolesas the name of the field, with an hint to the incorrect index[1]
Example 5
var data = {
name: 'test',
roles: ['admin'],
gender: ['waste']
};
This example validates to false with the error:
[1] "0" must be one of [male, female]
- Observation: Here I know, that the field with the name
"0"throws the error. - Issue: Here, I expect
genderas the name of the field, with an hint to the incorrect index[0]
Issue
The Examples 3, 4 and 5 show, that the index of an incorrect array entry is returned instead of the field name. Based on the field name ("0" and "1"), I do not know which field throws the error. I just know an index.
Note: Actually the problem occured while using react-validation-mixin, where I can get the error message for a given field with this.getValidationMessages('name');. The field name is set to "0", "1", ...
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugBug or defectBug or defect