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

Object with required fields passes validation and is missing default empty object #3911

Closed
4 tasks done
kylie-marshall opened this issue Oct 18, 2023 · 2 comments
Closed
4 tasks done

Comments

@kylie-marshall
Copy link
Contributor

kylie-marshall commented Oct 18, 2023

Prerequisites

What theme are you using?

core

Version

5.13.2 (latest on playground)

Current Behavior

Validation passes and no default object is created

Expected Behavior

Validation should error
In version 4, the object added a default {} to the form data which allowed ajv to trigger the validation. Now, the empty object is not being added by default.

Steps To Reproduce

  1. Have a schema with an object and a property inside that object is required but the object itself is not required
  2. Disable HTML 5 validation
  3. Form data is empty {} or undefined
  4. Save the form without adding any data
  5. Observe form passed validation and no errors were displayed

Environment

Playground environment

Anything else?

Playground link with example

Example schema

{
  "title": "A registration form",
  "description": "A simple form example.",
  "type": "object",
  "properties": {
    "testobject": {
      "type": "object",
      "required": [
        "firstName",
        "lastName"
      ],
      "properties": {
        "firstName": {
          "type": "string",
          "title": "First name"
        },
        "lastName": {
          "type": "string",
          "title": "Last name"
        }
      }
    }
  }
}

I've tested with both ajv6 and ajv8 with the same result

Tried to update the emptyobjectfields property but this didnt fix it. This setting says that it should populate defaults for non-empty objects (which worked in v4 as the legacy behavior) but it doesnt anymore

@kylie-marshall kylie-marshall added bug needs triage Initial label given, to be assigned correct labels and assigned labels Oct 18, 2023
@nickgros
Copy link
Contributor

@kyliem29 Hi, the behavior you were expecting that was present in v4 was actually a bug that many others had reported. To get your schema to work, you will need to require the testobject property.

See this playground example

@nickgros nickgros added awaiting response possibly close To confirm if this issue can be closed and removed bug needs triage Initial label given, to be assigned correct labels and assigned labels Oct 20, 2023
@stale stale bot removed possibly close To confirm if this issue can be closed labels Oct 20, 2023
@kylie-marshall
Copy link
Contributor Author

kylie-marshall commented Oct 23, 2023

ok, understood. Thank you for the quick reply

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

No branches or pull requests

2 participants