From 6eab4dc3a3563604157f7e9bc5d551ea14bd9a7d Mon Sep 17 00:00:00 2001 From: Gildas Garcia Date: Wed, 18 Sep 2019 15:04:30 +0200 Subject: [PATCH] Fix TabbedForm does not detect errors when source is a path on v2 Fixes #3695 --- packages/ra-ui-materialui/src/form/TabbedForm.js | 4 +++- packages/ra-ui-materialui/src/form/TabbedForm.spec.js | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/ra-ui-materialui/src/form/TabbedForm.js b/packages/ra-ui-materialui/src/form/TabbedForm.js index 69f390c7bb3..f6ff53e5a8d 100644 --- a/packages/ra-ui-materialui/src/form/TabbedForm.js +++ b/packages/ra-ui-materialui/src/form/TabbedForm.js @@ -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'; @@ -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]; diff --git a/packages/ra-ui-materialui/src/form/TabbedForm.spec.js b/packages/ra-ui-materialui/src/form/TabbedForm.spec.js index 1ee335025ff..8aec9b0b9b7 100644 --- a/packages/ra-ui-materialui/src/form/TabbedForm.spec.js +++ b/packages/ra-ui-materialui/src/form/TabbedForm.spec.js @@ -115,6 +115,9 @@ describe('', () => { const collectErrors = () => ({ field1: 'required', field5: 'required', + field7: { + test: 'required', + }, }); const state = {}; const props = { @@ -137,11 +140,17 @@ describe('', () => { 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']); }); }); });