This repository was archived by the owner on Aug 23, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import isPlainObject from 'lodash/isPlainObject';
4
4
import every from 'lodash/every' ;
5
5
import some from 'lodash/some' ;
6
6
import findKey from 'lodash/findKey' ;
7
+ import get from 'lodash/get' ;
7
8
8
9
import { initialFieldState } from '../reducers/form-reducer' ;
9
10
@@ -48,9 +49,10 @@ function getValue(value) {
48
49
}
49
50
50
51
function getForm ( state , model ) {
51
- const formStateKey = findKey ( state , { model } ) ;
52
-
53
- return state [ formStateKey ] ;
52
+ const path = model . split ( '.' ) ;
53
+ const modelRoot = path . length === 1 ? state : get ( state , path . slice ( 0 , path . length - 1 ) ) ;
54
+ const formStateKey = findKey ( modelRoot , { model } ) ;
55
+ return modelRoot && modelRoot [ formStateKey ] ;
54
56
}
55
57
56
58
function getValidity ( validators , value ) {
Original file line number Diff line number Diff line change @@ -592,4 +592,34 @@ describe('<Form> component', () => {
592
592
assert . equal ( timesSubmitCalled , 1 ) ;
593
593
} ) ;
594
594
} ) ;
595
+
596
+ describe ( 'deep state path' , ( ) => {
597
+ const fromsReducer = combineReducers ( {
598
+ testForm : formReducer ( 'forms.test' ) ,
599
+ test : modelReducer ( 'forms.test' , {
600
+ foo : '' ,
601
+ bar : '' ,
602
+ } ) ,
603
+ } ) ;
604
+ const store = applyMiddleware ( thunk ) ( createStore ) ( combineReducers ( {
605
+ forms : fromsReducer ,
606
+ } ) ) ;
607
+
608
+ const form = TestUtils . renderIntoDocument (
609
+ < Provider store = { store } >
610
+ < Form model = "forms.test" onSubmit = { ( ) => { } } />
611
+ </ Provider >
612
+ ) ;
613
+
614
+ const component = TestUtils . findRenderedComponentWithType ( form , Form ) ;
615
+ const props = component . renderedElement . props ;
616
+
617
+ it ( 'should resolve the model value' , ( ) => {
618
+ assert . containSubset ( props . modelValue , { foo : '' , bar : '' } ) ;
619
+ } ) ;
620
+
621
+ it ( 'should resolve the form value' , ( ) => {
622
+ assert . containSubset ( props . formValue , { valid : true , model : 'forms.test' } ) ;
623
+ } ) ;
624
+ } ) ;
595
625
} ) ;
You can’t perform that action at this time.
0 commit comments