feat(form): add setValue method to FormGroup class (#191)

This commit is contained in:
Neil An 2022-11-12 16:15:54 -05:00 committed by GitHub
parent 3faabb2348
commit 31884a1757
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -101,6 +101,16 @@ const submit: Submit = {
type: "submit", type: "submit",
}; };
const values = {
firstName: "James",
lastName: "Bond",
email: "james.bond@gmail.com",
country: "U.S.A",
eligible: "yes"
}
infoForm.setValue(values);
infoForm.name = "Application Form"; infoForm.name = "Application Form";
skillsForm.name = "Skills"; skillsForm.name = "Skills";

View file

@ -18,4 +18,8 @@ export class FormGroup {
get(name: string): FormControl | undefined { get(name: string): FormControl | undefined {
return this.controls.find((control) => control.name === name); return this.controls.find((control) => control.name === name);
} }
setValue(values: object) {
Object.keys(values).forEach((name) => this.get(name)?.setValue(values[name as keyof object]));
}
} }