Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.

getValidationMessages is empty for arrays #42

Closed
boldt opened this issue Sep 21, 2015 · 4 comments
Closed

getValidationMessages is empty for arrays #42

boldt opened this issue Sep 21, 2015 · 4 comments
Assignees
Labels

Comments

@boldt
Copy link

boldt commented Sep 21, 2015

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
Copy link
Owner

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 jurassix added the bug label Sep 21, 2015
@jurassix jurassix self-assigned this Sep 21, 2015
@jurassix jurassix mentioned this issue Sep 21, 2015
@jurassix
Copy link
Owner

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

@jurassix
Copy link
Owner

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

@boldt
Copy link
Author

boldt commented Sep 24, 2015

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants