I am working with a form group where I map the values from the form to an object type in order to make a request to edit the item.
This is my form structure:
public companyForm = new FormGroup(
{
generalInfo: new FormGroup({
name: new FormControl('', [Validators.required, Validators.maxLength(this.maxLength)]),
active: new FormControl(false)
}),
address: new FormGroup({
street: new FormControl('', [Validators.required, Validators.maxLength(this.maxLength)]),
streetNumber: new FormControl('', [Validators.required]),
postalCode: new FormControl('', [Validators.required]),
city: new FormControl('', [Validators.required]),
country: new FormControl('', [Validators.required])
})
})
Here is the CompanyEdit object structure:
name: formValue.generalInfo.name,
active: formValue.generalInfo.active,
address: {
street: formValue.address.street,
city: formValue.address.city,
streetNumber: formValue.address.streetNumber,
postalCode: formValue.address.postalCode
},
country: formValue.address.country
The field names and nesting structure do not align. When editing, I need to send only the changed controls on the form. Is there a recommended way to identify the dirty controls and map them to my object type?