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

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

Open
4 tasks done
chibacchie opened this issue Nov 29, 2024 · 5 comments · May be fixed by ajv-validator/ajv#2515
Open
4 tasks done

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

chibacchie opened this issue Nov 29, 2024 · 5 comments · May be fixed by ajv-validator/ajv#2515

Comments

@chibacchie
Copy link
Contributor

chibacchie commented Nov 29, 2024

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

@chibacchie chibacchie added bug needs triage Initial label given, to be assigned correct labels and assigned labels Nov 29, 2024
@heath-freenome
Copy link
Member

@chibacchie does your fix in #4398 also fix this issue?

@heath-freenome heath-freenome added awaiting response and removed needs triage Initial label given, to be assigned correct labels and assigned labels Dec 6, 2024
@chibacchie
Copy link
Contributor Author

@heath-freenome I did not fix this issue in #4398. To fix this issue, we may:

  1. Ask ajv to enclose raw property names with quotes
  2. Improve transformRJSFValidationErrors() to handle property and deps

@heath-freenome
Copy link
Member

@chibacchie The probability of AJV making that change is lower than fixing our code. Is that something that you are willing to attempt?

chibacchie added a commit to chibacchie/react-jsonschema-form that referenced this issue Dec 16, 2024
…:title. This fix only applicable if we use an ajv-i18n localizer. Ref. rjsf-team#4402.
chibacchie added a commit to chibacchie/react-jsonschema-form that referenced this issue Dec 16, 2024
…:title. This fix only applicable if we use an ajv-i18n localizer. Ref. rjsf-team#4402.
@chibacchie
Copy link
Contributor Author

chibacchie commented Dec 16, 2024

@heath-freenome Indeed. I made a PR which is only applicable if we use an ajv-18n localizer (See #4417). For the case without localizer, I plan to submit a PR for ajv as I don't have any idea to fix this issue without changing ajv.

@TheOneTheOnlyJJ
Copy link

I agree, we should do our best to request consistency from ajv.

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

Successfully merging a pull request may close this issue.

3 participants