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

Fix(@rjsf/antd): Check for errors.length #2576

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ should change the heading of the (upcoming) version to include a major version b
- Added global `readonly` flag to the `Form` (https://github.com/rjsf-team/react-jsonschema-form/pull/2554)
- Enable source maps in playground, for development (https://github.com/rjsf-team/react-jsonschema-form/pull/2568)

# v3.1.1 (upcoming)

## @rjsf/antd
- Do not show errors if `extraErrors` has `[]` (https://github.com/rjsf-team/react-jsonschema-form/pull/2576).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this up to the 5.0.0-beta.3 section?

# v3.1.0

## @rjsf/core
Expand Down
6 changes: 3 additions & 3 deletions packages/antd/src/templates/FieldTemplate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const FieldTemplate = ({
const renderFieldErrors = () =>
[...new Set(rawErrors)].map((error) => (
<div key={`field-${id}-error-${error}`}>{error}</div>
));
));

return (
<WrapIfAdditional
Expand All @@ -66,13 +66,13 @@ const FieldTemplate = ({
colon={colon}
extra={description}
hasFeedback={schema.type !== "array" && schema.type !== "object"}
help={(!!rawHelp && help) || (!!rawErrors && renderFieldErrors())}
help={(!!rawHelp && help) || (!!rawErrors?.length && renderFieldErrors())}
htmlFor={id}
label={displayLabel && label}
labelCol={labelCol}
required={required}
style={wrapperStyle}
validateStatus={rawErrors ? "error" : undefined}
validateStatus={rawErrors?.length ? 'error' : undefined}
wrapperCol={wrapperCol}
>
{children}
Expand Down
52 changes: 52 additions & 0 deletions packages/antd/test/EmptyErrorsArray.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be willing to add this to the Array.test.js instead, at the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import React from 'react'

is already in Array.test.js

Copy link
Member

@heath-freenome heath-freenome Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure you understand what I mean... You created a new EmptyErrorsArray.test.js file... Can you instead, copy the two tests and paste them at around line 77 in the Array.test.js file? Also, you'll need to now pass the required validator={validator} parameter into the Form

import renderer from 'react-test-renderer';

import '../__mocks__/matchMedia.mock';
import Form from '../src';

const { describe, expect, test } = global;

describe("array fields", () => {
test("has errors", () => {
const schema = {
type: 'object',
properties: {
name: {
type: 'string',
}
}
};
const tree = renderer
.create(<Form schema={schema} extraErrors={{ name: { __errors: ["Bad input"] } }} />)
.toJSON();
expect(tree).toMatchSnapshot();
});
test("no errors", () => {
const schema = {
type: 'object',
properties: {
name: {
type: 'string',
}
}
};
const tree = renderer
.create(<Form schema={schema} />)
.toJSON();
expect(tree).toMatchSnapshot();
});
test("empty errors array", () => {
const schema = {
type: 'object',
properties: {
name: {
type: 'string',
}
}
};
const tree = renderer
.create(<Form schema={schema} extraErrors={{ name: { __errors: [] } }} />)
.toJSON();
expect(tree).toMatchSnapshot();
});
});
Loading