Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TabbedForm does not detect errors when source is a path on v2 #3711

Merged
merged 1 commit into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']);
});
});
});