Skip to content

Commit 3276b80

Browse files
authored
Merge pull request #925 from rvsia/submitErrors
fix(all): add support for submit errors
2 parents 53319cf + 9a80e26 commit 3276b80

File tree

34 files changed

+117
-43
lines changed

34 files changed

+117
-43
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const validationError = (meta, validateOnMount) => {
22
if (validateOnMount) {
3-
return meta.error;
3+
return meta.error || meta.submitError;
44
}
55

6-
return meta.touched && meta.error;
6+
return meta.touched && (meta.error || meta.submitError);
77
};

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const DynamicArray = ({ ...props }) => {
134134
...buttonLabels
135135
};
136136

137-
const { dirty, submitFailed, error } = meta;
137+
const { dirty, submitFailed, error, submitError } = meta;
138138
const isError = (dirty || submitFailed) && error && typeof error === 'string';
139139
return (
140140
<AntForm
@@ -228,10 +228,10 @@ const DynamicArray = ({ ...props }) => {
228228
)}
229229
</Row>
230230
</Col>
231-
{isError && (
231+
{(isError || submitError) && (
232232
<Col span={12}>
233233
<Typography.Text type="danger" {...ErrorMessageProps}>
234-
{typeof error === 'object' ? error.name : error}
234+
{typeof error === 'object' ? error.name : error || submitError}
235235
</Typography.Text>
236236
</Col>
237237
)}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,21 @@ describe('formFields generated tests', () => {
289289
).toEqual(true);
290290
}
291291
});
292+
293+
it('renders with submitError', async () => {
294+
const wrapper = mount(<RendererWrapper schema={schema} onSubmit={() => ({ [field.name]: errorText })} />);
295+
await act(async () => {
296+
wrapper.find('form').simulate('submit');
297+
});
298+
wrapper.update();
299+
expect(
300+
wrapper
301+
.find('.ant-form-item-explain')
302+
.last()
303+
.text()
304+
).toEqual(errorText);
305+
expect(wrapper.find('.ant-form-item-has-error').length).toBeGreaterThanOrEqual(1);
306+
});
292307
});
293308
});
294309
});

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
});

packages/carbon-component-mapper/src/files/checkbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Wrapper.propTypes = {
3131
const SingleCheckbox = (props) => {
3232
const { input, meta, validateOnMount, helperText, WrapperProps, ...rest } = useFieldApi(prepareProps({ ...props, type: 'checkbox' }));
3333

34-
const invalid = (meta.touched || validateOnMount) && meta.error;
34+
const invalid = (meta.touched || validateOnMount) && (meta.error || meta.submitError);
3535

3636
const warnText = (meta.touched || validateOnMount) && meta.warning;
3737

packages/carbon-component-mapper/src/files/date-picker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import HelperTextBlock from '../common/helper-text-block';
1010
const DatePicker = (props) => {
1111
const { input, datePickerType, meta, DatePickerProps, validateOnMount, helperText, WrapperProps, ...rest } = useFieldApi(prepareProps(props));
1212

13-
const invalid = (meta.touched || validateOnMount) && meta.error;
13+
const invalid = (meta.touched || validateOnMount) && (meta.error || meta.submitError);
1414
const warnText = (meta.touched || validateOnMount) && meta.warning;
1515

1616
return (

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const FieldArray = (props) => {
7979
...buttonLabels
8080
};
8181

82-
const invalid = (meta.touched || validateOnMount) && !Array.isArray(meta.error) && meta.error;
82+
const invalid = (meta.touched || validateOnMount) && !Array.isArray(meta.error) && (meta.error || meta.submitError);
8383

8484
return (
8585
<FormGroup

packages/carbon-component-mapper/src/files/radio.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Radio = (props) => {
1212
prepareProps({ type: 'radio', ...props })
1313
);
1414

15-
const invalid = (meta.touched || validateOnMount) && meta.error;
15+
const invalid = (meta.touched || validateOnMount) && (meta.error || meta.submitError);
1616
const warnText = (meta.touched || validateOnMount) && meta.warning;
1717

1818
return (

0 commit comments

Comments
 (0)