Skip to content

Commit 02e6dff

Browse files
wanghoppehoppe
andauthored
populate form setValues to subForm (#2801)
* fix: npm run watch on packages * populate setValues to subForm * back to deep copy --------- Co-authored-by: hoppe <hoppewang@microsoft.com>
1 parent 40b3354 commit 02e6dff

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

packages/bonito-core/src/form/__tests__/form.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,18 @@ describe("Form tests", () => {
284284
},
285285
}
286286
);
287+
288+
// form.setValues() should set the values of the subForm
289+
form.setValues({
290+
...form.values,
291+
answers: {
292+
color: "yellow",
293+
},
294+
});
295+
296+
expect(subForm.values).toEqual({
297+
color: "yellow",
298+
});
287299
});
288300

289301
test("Validation", async () => {

packages/bonito-core/src/form/internal/form-impl.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ export class FormImpl<V extends FormValues> implements Form<V> {
256256
return;
257257
}
258258
this._values = values;
259+
for (const e of this.allEntries()) {
260+
if (e instanceof SubForm) {
261+
e.setValues(values[e.name]);
262+
}
263+
}
259264
this._formValuesChanged(values, oldValues);
260265
}
261266

0 commit comments

Comments
 (0)