Created
October 4, 2018 00:23
-
-
Save vmussak/80c2ff2db76ad4bb167f44c81916b162 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onSubmit(form) { | |
if (!this.saving) { | |
for (const control in form.controls) { | |
if (form.controls.hasOwnProperty(control)) { | |
form.controls[control].markAsTouched(); | |
form.controls[control].markAsDirty(); | |
} | |
} | |
if (!form.valid) { | |
this.element.nativeElement.querySelectorAll('form .ng-invalid')[0].focus(); | |
return false; | |
} | |
this.saving = true; | |
this.clienteService.cadastrar(this.info).subscribe(data => { | |
this.saving = false; | |
UiSnackbar.show({ | |
text: `Cliente cadastrado com sucesso.` | |
}); | |
this.router.navigate(['/cliente'], { replaceUrl: true }); | |
}, e => { | |
this.saving = false; | |
if(e.error.statusCode == 406){ | |
form.controls.cpf.setErrors({ duplicate: true }); | |
this.element.nativeElement.querySelector('#cpf').focus(); | |
} else { | |
UiSnackbar.show({ | |
text: 'Ocorreu um erro interno, tente novamente mais tarde.' | |
}); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment