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

Error management on required nested field #501

Open
olivier-robin31 opened this issue Jan 17, 2025 · 0 comments
Open

Error management on required nested field #501

olivier-robin31 opened this issue Jan 17, 2025 · 0 comments

Comments

@olivier-robin31
Copy link

olivier-robin31 commented Jan 17, 2025

Here is a schema where I declare the childA as required (childA is nested under root2):

{
  "properties": {
    "root1": {
      "type": "string",
      "description": "Root 1"
    },
    "root2": {
      "type": "object",
      "description": "Root 2",
      "properties": {
        "childA": {
          "type": "string",
          "title": "Child A (required)"
        },
        "childB": {
          "type": "string",
          "title": "Child B (not required)"
        }
      },
      "required": [
        "childA"
      ]
    }
  }
}

When I "play" with it, I don't understand the error management.
2 consecutive use cases:

  • both childA and childB are empty:
    => childA is in success ('has-success' and 'ng-valid' classes) although it must be filled => how can we indicate the problem on the field ?
    => root2 is in error ('has-error' class and error "message": "Missing required property: childA", "path": "#/childA")
    => the global form is valid => how can we disabled a submit button ?

  • childA still empty, and childB is filled:
    => childA still in success
    => root2 still in error (with the same error)
    => root2 has now a second error "message": "Missing required property: childA", "path": "#/root2"
    => the global form is now invalid and has the error "message": "Missing required property: childA", "path": "#/childA"

It's very confusing:

  • Why the required error is set on the parent of the field instead of the field itself like for other errors (minLength etc.) ?
  • Why on the first level (not nested fields) there is not the problem ?
  • Why the childA error is "locked" at the parent level (and is not raised at the global form) ? And why it is "unlocked" if childB is filled ?
  • What is the correct way to manage errors ? In our custom widget code, shall we look at control.errors ? or errorMessages ? or formProperty._errors ?
@olivier-robin31 olivier-robin31 changed the title Required nested field Error management on required nested field Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant