Skip to content

Commit 0d8e46c

Browse files
committed
fix(mui): add submit errors
1 parent fca2b47 commit 0d8e46c

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
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/mui-component-mapper/src/files/field-array.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,17 @@ const DynamicArray = ({ ...props }) => {
133133

134134
const classes = useFielArrayStyles();
135135

136-
const { dirty, submitFailed, error } = meta;
136+
const { dirty, submitFailed, error, submitError } = meta;
137137
const isError = (dirty || submitFailed) && error && typeof error === 'string';
138138

139139
return (
140140
<FormFieldGrid {...FormFieldGridProps} className={clsx(classes.fieldArrayGroup, FormFieldGridProps.classname)}>
141-
<FormControl component="fieldset" error={isError} {...FormControlProps} className={clsx(classes.formControl, FormControlProps.className)}>
141+
<FormControl
142+
component="fieldset"
143+
error={isError || submitError}
144+
{...FormControlProps}
145+
className={clsx(classes.formControl, FormControlProps.className)}
146+
>
142147
<FieldArray key={rest.input.name} name={rest.input.name} validate={arrayValidator}>
143148
{({ fields: { map, value = [], push, remove } }) => {
144149
const pushWrapper = () => {
@@ -204,9 +209,9 @@ const DynamicArray = ({ ...props }) => {
204209
))
205210
)}
206211
</Grid>
207-
{isError && (
212+
{(isError || submitError) && (
208213
<Grid item xs={12}>
209-
<FormHelperText>{error}</FormHelperText>
214+
<FormHelperText>{error || submitError}</FormHelperText>
210215
</Grid>
211216
)}
212217
</Grid>

packages/mui-component-mapper/src/tests/form-fields.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ describe('formFields', () => {
255255
).toEqual(true);
256256
}
257257
});
258+
259+
it('renders with error', () => {
260+
const wrapper = mount(<RendererWrapper schema={schema} onSubmit={() => ({ [field.name]: errorText })} />);
261+
wrapper.find('form').simulate('submit');
262+
expect(
263+
wrapper
264+
.find('.Mui-error')
265+
.last()
266+
.text()
267+
).toEqual(errorText);
268+
});
258269
});
259270
});
260271
});

0 commit comments

Comments
 (0)