Skip to content

Commit 3a41bba

Browse files
Merge pull request #83 from tjinauyeung/fix-invalid-modified-state-on-initialization
fix(create-form): use deep equal to determine if initial values are modified
2 parents 0930627 + 251b253 commit 3a41bba

File tree

5 files changed

+565
-21330
lines changed

5 files changed

+565
-21330
lines changed

lib/create-form.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ export const createForm = (config) => {
4242
const object = util.assignDeep($form, false);
4343

4444
for (let key in $form) {
45-
if ($form[key] !== initialValues[key]) {
46-
object[key] = true;
47-
}
45+
object[key] = !util.deepEqual($form[key], initialValues[key]);
4846
}
4947

5048
return object;

lib/util.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import isEqual from 'lodash.isequal';
12
import {forEach} from 'property-expr';
23

34
function subscribeOnce(observable) {
@@ -72,6 +73,8 @@ function getErrorsFromSchema(initialValues, schema, errors = {}) {
7273
return errors;
7374
}
7475

76+
const deepEqual = isEqual;
77+
7578
function assignDeep(object, value) {
7679
if (Array.isArray(object)) {
7780
return object.map((o) => assignDeep(o, value));
@@ -161,14 +164,15 @@ function getIn(schema, path, value, context) {
161164
}
162165

163166
export const util = {
164-
getErrorsFromSchema,
165167
assignDeep,
166168
cloneDeep,
169+
deepEqual,
170+
getErrorsFromSchema,
167171
getValues,
168172
isEmpty,
173+
isNullish,
169174
reach,
170175
set,
171176
subscribeOnce,
172177
update,
173-
isNullish,
174178
};

0 commit comments

Comments
 (0)