feat(form): add setValue
method to FormGroup class (#191)
This commit is contained in:
parent
3faabb2348
commit
31884a1757
2 changed files with 14 additions and 0 deletions
|
@ -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";
|
||||||
|
|
||||||
|
|
|
@ -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]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue