I am trying to create a form for a user that allows me to associate phone numbers with a user. Is this possible with the current implementation of reactive forms? For example, I would like the bottom form to accept potentially many phone numbers. My foreground implementation will display a phone number field and will have a button that will add an additional phone number field.
userForm = new FormGroup({
firstName: new FormControl('', Validators.required),
lastName: new FormControl('', Validators.required),
phoneNumber: new FormControl('', Validators.required)
});
My hacking solution will be
userForm = new FormGroup({
firstName: new FormControl('', Validators.required),
lastName: new FormControl('', Validators.required),
phoneNumber: new FormControl('', Validators.required),
phoneNumber1: new FormControl(),
phoneNumber2: new FormControl(),
phoneNumber3: new FormControl(),
phoneNumber4: new FormControl()
});
I could suppress the extra phone fields until the add additional phone number button is pressed.
source
share