Skip to content

Commit df103ab

Browse files
authored
Merge pull request #924 from rvsia/addSubmitErrorsToPF4
feat(pf4): add support for submit errors
2 parents f9616f4 + ca5aa83 commit df103ab

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

packages/pf4-component-mapper/src/common/form-group.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const FormGroup = ({ label, isRequired, helperText, meta, description, hideLabel
1010
label={!hideLabel && label}
1111
fieldId={id}
1212
helperText={(meta.touched && meta.warning) || helperText}
13-
helperTextInvalid={meta.error}
13+
helperTextInvalid={meta.error || meta.submitError}
1414
{...showError(meta)}
1515
{...FormGroupProps}
1616
>

packages/pf4-component-mapper/src/common/show-error.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
const showError = ({ error, touched, warning }) => {
1+
const showError = ({ error, touched, warning, submitError }) => {
22
if (touched && error) {
33
return { validated: 'error' };
44
}
55

6+
if (touched && submitError) {
7+
return { validated: 'error' };
8+
}
9+
610
if (touched && warning) {
711
return { validated: 'warning' };
812
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ const DynamicArray = ({ ...props }) => {
7575
const { arrayValidator, label, description, fields: formFields, defaultItem, meta, minItems, maxItems, noItemsMessage, ...rest } = useFieldApi(
7676
props
7777
);
78-
const { dirty, submitFailed, error } = meta;
79-
const isError = (dirty || submitFailed) && error && typeof error === 'string';
78+
const { dirty, submitFailed, error, submitError } = meta;
79+
const isError = (dirty || submitFailed) && (error || submitError) && (typeof error === 'string' || typeof submitError === 'string');
8080

8181
return (
8282
<FieldArray key={rest.input.name} name={rest.input.name} validate={arrayValidator}>
@@ -104,7 +104,7 @@ const DynamicArray = ({ ...props }) => {
104104
<GridItem sm={11}>
105105
{isError && (
106106
<FormHelperText isHidden={false} isError={true}>
107-
{error}
107+
{error || submitError}
108108
</FormHelperText>
109109
)}
110110
</GridItem>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,17 @@ describe('FormFields', () => {
482482
).toEqual(true);
483483
}
484484
});
485+
486+
it('renders with submit error', () => {
487+
const wrapper = mount(<RendererWrapper schema={schema} onSubmit={() => ({ [field.name]: errorText })} />);
488+
wrapper.find('form').simulate('submit');
489+
expect(
490+
wrapper
491+
.find('.pf-m-error')
492+
.last()
493+
.text()
494+
).toEqual(errorText);
495+
});
485496
});
486497
});
487498
});

0 commit comments

Comments
 (0)