I have a reactive form in angular 2 which can get called through an add button for a new form or an edit button to update existing details. If the user selects the edit button the email input should be disabled. I have the code below but whenever the user selects edit, the input is not disabled. If i set disabled to be true in the addForm method and select the edit button then the email input is disabled
public addForm(event: string) : FormGroup {
this.userForm = this.fb.group({
firstName: ['',
[ Validators.required,
Validators.maxLength(ManageUsersConstants.maxLengthName)
]],
lastName: ['',
[ Validators.required,
Validators.maxLength(ManageUsersConstants.maxLengthName)]
],
email: [{value: '', disabled : false}],
}),
});
}
public editForm(event: string, editValues : any) : FormGroup {
this.userForm = this.fb.group({
firstName: [editValues.firstName, [
Validators.required,
Validators.maxLength(ManageUsersConstants.maxLengthName)]],
lastName: [editValues.lastName,
[ Validators.required,
Validators.maxLength(ManageUsersConstants.maxLengthName)]],
email: [{value: editValues.email, disabled: true}],
});
}
this.userForm.get('email').disable();(I think, haven't touched one in a little bit 😅)