Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit c61c2b5

Browse files
committed
Reverting last commit
1 parent 2508a45 commit c61c2b5

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

src/utils/create-field.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,3 @@ export function createFormState(model, values, customInitialFieldState, options
6363

6464
return state;
6565
}
66-
67-
export function insertFormField(form, fieldModelPath, fieldValue) {
68-
const subPath = fieldModelPath[0];
69-
70-
if (form[subPath]) {
71-
return {
72-
...form,
73-
[subPath]: insertFormField(form[subPath], fieldModelPath.slice(1), fieldValue[subPath]),
74-
};
75-
}
76-
77-
return {
78-
...form,
79-
[subPath]: fieldOrForm(subPath, fieldValue),
80-
};
81-
}

src/utils/update-field.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
import i from 'icepick';
12
import get from './get';
23
import mapValues from './map-values';
3-
import { updateFieldState, fieldOrForm } from './create-field';
4+
import { createInitialState } from '../reducers/form-reducer';
5+
import { updateFieldState } from './create-field';
46
import assocIn from './assoc-in';
57
import invariant from 'invariant';
68

9+
function tempInitialState(path, initialValue = null) {
10+
if (path.length === 1) return { [path[0]]: initialValue };
11+
12+
return {
13+
[path[0]]: tempInitialState(path.slice(1), initialValue),
14+
};
15+
}
16+
717
export function getFieldAndForm(formState, modelPath) {
818
let field = get(formState, modelPath);
919
let form = formState;
@@ -14,9 +24,10 @@ export function getFieldAndForm(formState, modelPath) {
1424

1525
if (!field) {
1626
const initialValue = get(formState.$form.initialValue, modelPath);
17-
const formModel = formState.$form.model;
1827

19-
form = assocIn(formState, modelPath, fieldOrForm([formModel, ...modelPath], initialValue));
28+
form = i.merge(createInitialState(
29+
formState.$form.model,
30+
tempInitialState(modelPath, initialValue)), formState);
2031

2132
field = get(form, modelPath);
2233
}

0 commit comments

Comments
 (0)