Skip to content

Commit

Permalink
populate form setValues to subForm (#2801)
Browse files Browse the repository at this point in the history
* fix: npm run watch on packages

* populate setValues to subForm

* back to deep copy

---------

Co-authored-by: hoppe <hoppewang@microsoft.com>
  • Loading branch information
wanghoppe and hoppe committed Sep 14, 2023
1 parent 40b3354 commit 02e6dff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/bonito-core/src/form/__tests__/form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,18 @@ describe("Form tests", () => {
},
}
);

// form.setValues() should set the values of the subForm
form.setValues({
...form.values,
answers: {
color: "yellow",
},
});

expect(subForm.values).toEqual({
color: "yellow",
});
});

test("Validation", async () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/bonito-core/src/form/internal/form-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ export class FormImpl<V extends FormValues> implements Form<V> {
return;
}
this._values = values;
for (const e of this.allEntries()) {
if (e instanceof SubForm) {
e.setValues(values[e.name]);
}
}
this._formValuesChanged(values, oldValues);
}

Expand Down

0 comments on commit 02e6dff

Please sign in to comment.