When I execute formBuild.group
, I am creating two temporary values for validation purposes only. These values are not intended to be saved in the database, so I need to remove them before saving.
profile.component.ts:
profileForm: FormGroup;
constructor(){
this.profileForm = this.createPerfilForm();
}
createProfileForm() {
return this.formBuilder.group({
id: [this.perfil.id],
name: [this.perfil.name, [Validators.required, Validators.minLength(5), Validators.maxLength(45)]],
email: [this.perfil.email, [Validators.required, Validators.email]],
password: [''],
passwordConfirm: ['', [confirmPassword]],
});
}
saveProfile(){
// Need to strip out password and passwordConfirm
//before database save
this.authService.updateProfile(this.profileForm.value);
}
I must exclude this.profileForm.value
from the password
and passwordConfirm
fields since these values should not be stored in the database.