Skip to content

Commit

Permalink
Fix TabbedForm does not detect errors when source is a path on v2
Browse files Browse the repository at this point in the history
Fixes #3695
  • Loading branch information
djhi committed Sep 18, 2019
1 parent 2bd76ee commit 6eab4dc
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 @@ -14,6 +14,7 @@ import Divider from '@material-ui/core/Divider';
import Tabs from '@material-ui/core/Tabs';
import { withStyles, createStyles } from '@material-ui/core/styles';
import { getDefaultValues, translate, REDUX_FORM_NAME } from 'ra-core';
import get from 'lodash/get';

import Toolbar from './Toolbar';
import CardContentInner from '../layout/CardContentInner';
Expand Down Expand Up @@ -271,7 +272,8 @@ export const findTabsWithErrors = (

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 @@ -115,6 +115,9 @@ describe('<TabbedForm />', () => {
const collectErrors = () => ({
field1: 'required',
field5: 'required',
field7: {
test: 'required',
},
});
const state = {};
const props = {
Expand All @@ -137,11 +140,17 @@ 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(state, props, collectErrors);
assert.deepEqual(tabs, ['tab1', 'tab3']);
assert.deepEqual(tabs, ['tab1', 'tab3', 'tab4']);
});
});
});

0 comments on commit 6eab4dc

Please sign in to comment.