Skip to content

Commit

Permalink
Merge pull request #3710 from marmelab/fix-tabbed-form-errors-detection
Browse files Browse the repository at this point in the history
Fix TabbedForm does not detect errors when source is a path
  • Loading branch information
fzaninotto authored Oct 3, 2019
2 parents 6e7a4da + edb86db commit 5ef1a29
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/ra-ui-materialui/src/form/TabbedForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useInitializeFormWithRecord,
sanitizeEmptyValues,
} from 'ra-core';
import get from 'lodash/get';

import getFormInitialValues from './getFormInitialValues';
import Toolbar from './Toolbar';
Expand Down Expand Up @@ -287,7 +288,8 @@ export const findTabsWithErrors = (children, errors) => {

if (
inputs.some(
input => isValidElement(input) && errors[input.props.source]
input =>
isValidElement(input) && get(errors, input.props.source)
)
) {
return [...acc, child.props.label];
Expand Down
11 changes: 10 additions & 1 deletion packages/ra-ui-materialui/src/form/TabbedForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ describe('<TabbedForm />', () => {
const errors = {
field1: 'required',
field5: 'required',
field7: {
test: 'required',
},
};
const children = [
createElement(
Expand All @@ -76,10 +79,16 @@ describe('<TabbedForm />', () => {
createElement('input', { source: 'field5' }),
createElement('input', { source: 'field6' })
),
createElement(
FormTab,
{ label: 'tab4' },
createElement('input', { source: 'field7.test' }),
createElement('input', { source: 'field8' })
),
];

const tabs = findTabsWithErrors(children, errors);
expect(tabs).toEqual(['tab1', 'tab3']);
expect(tabs).toEqual(['tab1', 'tab3', 'tab4']);
});
});
});

0 comments on commit 5ef1a29

Please sign in to comment.