From edb86dbc0e1c5491d5a63a2ecd63c88170db3abb Mon Sep 17 00:00:00 2001 From: Gildas Garcia Date: Wed, 18 Sep 2019 14:27:58 +0200 Subject: [PATCH] Fix TabbedForm does not detect errors when source is a path 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 7d261d02f00..3663582b4d8 100644 --- a/packages/ra-ui-materialui/src/form/TabbedForm.js +++ b/packages/ra-ui-materialui/src/form/TabbedForm.js @@ -11,6 +11,7 @@ import { useInitializeFormWithRecord, sanitizeEmptyValues, } from 'ra-core'; +import get from 'lodash/get'; import getFormInitialValues from './getFormInitialValues'; import Toolbar from './Toolbar'; @@ -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]; diff --git a/packages/ra-ui-materialui/src/form/TabbedForm.spec.js b/packages/ra-ui-materialui/src/form/TabbedForm.spec.js index c8fde6415b5..5dfb6d98c47 100644 --- a/packages/ra-ui-materialui/src/form/TabbedForm.spec.js +++ b/packages/ra-ui-materialui/src/form/TabbedForm.spec.js @@ -56,6 +56,9 @@ describe('', () => { const errors = { field1: 'required', field5: 'required', + field7: { + test: 'required', + }, }; const children = [ createElement( @@ -76,10 +79,16 @@ 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(children, errors); - expect(tabs).toEqual(['tab1', 'tab3']); + expect(tabs).toEqual(['tab1', 'tab3', 'tab4']); }); }); });