Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent syntax for property paths in error objects #818

Closed
2 tasks done
Steffan-Ennis opened this issue Jan 19, 2018 · 1 comment · Fixed by #1205
Closed
2 tasks done

Inconsistent syntax for property paths in error objects #818

Steffan-Ennis opened this issue Jan 19, 2018 · 1 comment · Fixed by #1205

Comments

@Steffan-Ennis
Copy link

Prerequisites

  • I have read the documentation;
  • In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.

Description

Error objects in the errors collection passed into the transformErrors callback are inconsistent

Field paths have two different syntaxes.

Property keys can delimited by . and also encapsulated by [] when special characters or white space is present

This may be intentional but it is a breaking change introduced in v1.0.0.
It would be nice to have this noted in the release notes.

Steps to Reproduce

  1. Use the following schema and transformErrors
const transformErrors = errors => {
  errors.forEach(error => {
    console.log(error.property)
  })
}

const schema = {
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string"
    },
    "first-name": {
      "type": "string"
    }
  },
  "required": [
    "first-name",
    "firstName"
  ]
}
  1. submit the form and leave firstName and first-name emtpy

Expected behavior

-> "['firstName']"
-> "['first-name']"

Actual behavior

-> ".firstName"
-> "['first-name']"

Version

1.0.0

@epicfaace
Copy link
Member

Playground link

I'm guessing we don't want to go with the "expected behavior", but rather just document this? i.e., error.property is equal to ajv's dataPath, which is just Javascript property accessor notation to get the value.

epicfaace added a commit to epicfaace/react-jsonschema-form that referenced this issue Jan 20, 2019
epicfaace added a commit that referenced this issue Mar 6, 2019
* #838 return schemaPath in transformErrors

* #818 document structure of errors object in transformErrors

* fix: take into account ajv bug

* doc: re-add doc for transformErrors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants