Skip to content

Commit fca2b47

Browse files
committed
fix(ant): add support for submitErrors
1 parent f651375 commit fca2b47

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
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
});

0 commit comments

Comments
 (0)