Skip to content

Commit f651375

Browse files
committed
fix(blueprint): add support for submitErrors
1 parent edadd7e commit f651375

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

packages/blueprint-component-mapper/src/files/field-array.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ const FieldArray = (props) => {
6868

6969
const { required } = useContext(BlueprintContext);
7070

71-
const { error, touched } = meta;
72-
const showError = (validateOnMount || touched) && error;
71+
const { error, touched, submitError } = meta;
72+
const showError = (validateOnMount || touched) && (error || submitError);
7373

7474
const text = showError ? error : helperText || description;
7575

packages/blueprint-component-mapper/src/files/form-group.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export const FormGroupInternal = ({
2222
}) => {
2323
const { required } = useContext(BlueprintContext);
2424

25-
const { error, touched, warning } = meta;
26-
const showError = (validateOnMount || touched) && error;
25+
const { error, touched, warning, submitError } = meta;
26+
const showError = (validateOnMount || touched) && (error || submitError);
2727
const showWarning = (validateOnMount || touched) && warning;
2828

2929
const text = showError || showWarning || helperText || description;

packages/blueprint-component-mapper/src/tests/components.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,18 @@ describe('formFields generated tests', () => {
264264
}
265265
}
266266
});
267+
268+
it('renders with error', () => {
269+
const wrapper = mount(<RendererWrapper schema={schema} onSubmit={() => ({ [field.name]: errorText })} />);
270+
wrapper.find('form').simulate('submit');
271+
expect(
272+
wrapper
273+
.find('.bp3-form-helper-text')
274+
.last()
275+
.text()
276+
).toEqual(errorText);
277+
expect(wrapper.find('.bp3-intent-danger').length).toBeGreaterThanOrEqual(1);
278+
});
267279
});
268280
});
269281
});

0 commit comments

Comments
 (0)