jurassix / react-validation-mixin

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

getValidationMessages is empty for arrays #42

Closed boldt closed 8 years ago

boldt commented 8 years ago

This bug is related to #39 (The index of an incorrect array entry is returned instead of the field name)

Observtion: The errors object returned by joi-validation-strategy does look like this:

data: Array[0]
data.0: Array[1]
data.1: Array[1]
data.2: Array[1]

Thus, this.getValidationMessages('data') is emtpy, while this.getValidationMessages('data.0'), this.getValidationMessages('data.1'), this.getValidationMessages('data.2') are set.

My current workaround: Limit the numer of elemenets and then call:

  {this.props.getValidationMessages('data.0').map(this.renderHelpText)}
  {this.props.getValidationMessages('data.1').map(this.renderHelpText)}
  {this.props.getValidationMessages('data.2').map(this.renderHelpText)}
  {this.props.getValidationMessages('data.3').map(this.renderHelpText)}
  {this.props.getValidationMessages('data.4').map(this.renderHelpText)}
  {this.props.getValidationMessages('data.5').map(this.renderHelpText)}
  {this.props.getValidationMessages('data.6').map(this.renderHelpText)}
  {this.props.getValidationMessages('data.7').map(this.renderHelpText)}
  {this.props.getValidationMessages('data.8').map(this.renderHelpText)}
  {this.props.getValidationMessages('data.9').map(this.renderHelpText)}

Instead of:

  {this.props.getValidationMessages('data').map(this.renderHelpText)}

This can be also an issue for the joi-validation-strategy

[Edit] The paths data.0, data.1, ... are produced by Joi, and thus mapped 1:1.

jurassix commented 8 years ago

I've been waiting to update the joi-validation-strategy to account for nested object structures and arrays. I'll make this a priority to resolve. The real issue is with the naive formatting of errors by the strategy.

We can track this issue here and I'll reference this issue on the strategy side on check-in.

Thanks for the detailed report.

jurassix commented 8 years ago

This has been fixed with 5.2.0: https://github.com/jurassix/react-validation-mixin/releases/tag/v5.2.0

jurassix commented 8 years ago

Ensure you upgrade joi-validation-strategy to v0.2.1

boldt commented 8 years ago

Perfect. this.props.getValidationMessages('data') returns a list of errors now. Thank you!