jurassix / react-validation-mixin

Simple validation mixin (HoC) for React.
MIT License
283 stars 38 forks source link

getValidationMessages error for object validation #47

Closed boldt closed 8 years ago

boldt commented 8 years ago

Imagine the following Joi:

{
  thumbnail : {
    height : Joi.number().required()
  }
}

Calling getValidationMessages('thumbnail') returns me the following error: Uncaught TypeError: html.replace is not a function

Stacktrace:

decode  @   he.js:221
decode  @   decode.js:26
getValidationMessages   @   validationFactory.js:37
getValidationMessages   @   validationMixin.js:65

The issue is simple: decode.js does not check for objects. Thus, replace is called on an object instead of a string.

jurassix commented 8 years ago

I put together a test for this. It looks like all you need to do is the following:

getValidationMessages('thumbnail.height')
jurassix commented 8 years ago

Technically thumbnail is just an object but height is the Joi schema.

jurassix commented 8 years ago

This should work the same way as asking if this field is valid or to validate the field:

this.props.isValid('thumbnail.height')
this.props.handleValidation'(thumbnail.height')
this.props.getValidationMessages('thumbnail.height')