rjsf-team/react-jsonschema-form

Dependency errors do not show `title` or `ui:title`

Open

#4402 opened on Nov 29, 2024

View on GitHub
 (5 comments) (1 reaction) (0 assignees)TypeScript (13,175 stars) (2,136 forks)batch import
awaiting responsebughelp wanted

Description

Prerequisites

What theme are you using?

validator-ajv8

Version

5.23.1

Current Behavior

Dependency errors do not show title or ui:title.

const Ajv2019 = require('ajv/dist/2019');
const { customizeValidator } = require('@rjsf/validator-ajv8');

const schema = {
  type: 'object',
  properties: {
    creditCard: {
      type: 'number',
      title: 'Credit card',
    },
    billingAddress: {
      type: 'string',
      title: 'Billing address',
    },
  },
  dependentRequired: {
    creditCard: ['billingAddress'],
  },
};

const validator = customizeValidator({ AjvClass: Ajv2019 });
const result = validator.validateFormData({ creditCard: 1234567890 }, schema);
console.log(result.errors[0].message);

This results in must have property billingAddress when property creditCard is present.

Expected Behavior

must have property 'Billing address' when property 'Credit card' is present is expected.

There are two possible causes:

  1. ajv does not enclose raw property names with quotes (see here) while transformRJSFValidationErrors() expects property names are enclosed.
  2. transformRJSFValidationErrors() only handles missingProperty (see this block). property and deps should be handled as well.

Steps To Reproduce

Please see above.

Environment

- OS: Ubuntu 24.04
- Node: 18.20.2
- npm: 10.5.0

Anything else?

No response

Contributor guide