Skip to content

Dependency errors do not show title or ui:title #4402

Open
ajv-validator/ajv
#2515
@chibacchie

Description

@chibacchie

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions