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 @@ -586,4 +586,34 @@ describe('<Form> component', () => {
586
586
assert . equal ( timesSubmitCalled , 1 ) ;
587
587
} ) ;
588
588
} ) ;
589
+
590
+ describe ( 'deep state path' , ( ) => {
591
+ const fromsReducer = combineReducers ( {
592
+ testForm : formReducer ( 'forms.test' ) ,
593
+ test : modelReducer ( 'forms.test' , {
594
+ foo : '' ,
595
+ bar : '' ,
596
+ } ) ,
597
+ } ) ;
598
+ const store = applyMiddleware ( thunk ) ( createStore ) ( combineReducers ( {
599
+ forms : fromsReducer ,
600
+ } ) ) ;
601
+
602
+ const form = TestUtils . renderIntoDocument (
603
+ < Provider store = { store } >
604
+ < Form model = "forms.test" onSubmit = { ( ) => { } } />
605
+ </ Provider >
606
+ ) ;
607
+
608
+ const component = TestUtils . findRenderedComponentWithType ( form , Form ) ;
609
+ const props = component . renderedElement . props ;
610
+
611
+ it ( 'should resolve the model value' , ( ) => {
612
+ assert . containSubset ( props . modelValue , { foo : '' , bar : '' } ) ;
613
+ } ) ;
614
+
615
+ it ( 'should resolve the form value' , ( ) => {
616
+ assert . containSubset ( props . formValue , { valid : true , model : 'forms.test' } ) ;
617
+ } ) ;
618
+ } ) ;
589
619
} ) ;
You can’t perform that action at this time.
0 commit comments