Skip to content

Instantly share code, notes, and snippets.

@vmussak

vmussak/cliente.ts

Created Oct 4, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.