Skip to content

Commit

Permalink
se arreglo el formulario del register
Browse files Browse the repository at this point in the history
  • Loading branch information
matias1305 committed Dec 7, 2018
1 parent 1c85e31 commit 88fa0ae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 28 deletions.
2 changes: 0 additions & 2 deletions src/app/register/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ export class LoginComponent implements OnInit {
loginUser(){
this.submit = true;

console.log(this.form.controls);

if( this.form.valid ){
this.afAuth.auth.signInWithEmailAndPassword(this.form.value['email'], this.form.value['password'])
.then( (resp) => {
Expand Down
41 changes: 19 additions & 22 deletions src/app/register/register.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ <h3 class="box-title m-t-40 m-b-0">Datos de perfil</h3>
<div class="col-xs-12">
<input formControlName="name" class="form-control" type="text" placeholder="Nombre">
</div>
<div *ngIf="form.controls['name'].errors?.required && submit"><p class="text-danger">El nombre es requerido</p></div>
<div *ngIf="form.controls['name'].errors?.pattern && submit"><p class="text-danger">El nombre ingresado no es válido</p></div>
<div *ngIf="form.controls['name'].errors?.required && submit1"><p class="text-danger">El nombre es requerido</p></div>
<div *ngIf="form.controls['name'].errors?.pattern && submit1"><p class="text-danger">El nombre ingresado no es válido</p></div>
</div>

<div class="form-group m-t-10 row">
<div class="col-md-6">
<input formControlName="last_name1" class="form-control" type="text" placeholder="Apellido paterno">
<div *ngIf="form.controls['last_name1'].errors?.required && submit"><p class="text-danger">El apellido es requerido</p></div>
<div *ngIf="form.controls['last_name1'].errors?.pattern && submit"><p class="text-danger">El apellido ingresado no es válido</p></div>
<div *ngIf="form.controls['last_name1'].errors?.required && submit1"><p class="text-danger">El apellido es requerido</p></div>
<div *ngIf="form.controls['last_name1'].errors?.pattern && submit1"><p class="text-danger">El apellido ingresado no es válido</p></div>
</div>
<div class="col-md-6">
<input formControlName="last_name2" class="form-control" type="text" placeholder="Apellido materno">
<div *ngIf="form.controls['last_name1'].errors?.required && submit"><p class="text-danger">El apellido es requerido</p></div>
<div *ngIf="form.controls['last_name1'].errors?.pattern && submit"><p class="text-danger">El apellido ingresado no es válido</p></div>
<div *ngIf="form.controls['last_name2'].errors?.required && submit1"><p class="text-danger">El apellido es requerido</p></div>
<div *ngIf="form.controls['last_name2'].errors?.pattern && submit1"><p class="text-danger">El apellido ingresado no es válido</p></div>
</div>
</div>

<div class="form-group m-t-20">
<div class="col-xs-12">
<input formControlName="rut" class="form-control" type="text" placeholder="RUT">
</div>
<div *ngIf="form.controls['rut'].errors?.required && submit"><p class="text-danger">El RUT es requerido</p></div>
<div *ngIf="form.controls['rut'].errors?.pattern && submit"><p class="text-danger">El RUT ingresado no es válido</p></div>
<div *ngIf="form.controls['rut'].errors?.required && submit1"><p class="text-danger">El RUT es requerido</p></div>
<div *ngIf="form.controls['rut'].errors?.pattern && submit1"><p class="text-danger">El RUT ingresado no es válido</p></div>
</div>

<!-- <div class="form-group m-t-20">
Expand All @@ -51,12 +51,8 @@ <h3 class="box-title m-t-40 m-b-0">Datos de perfil</h3>

<div class="form-group text-center m-t-20">
<div class="col-xs-12">
<button (click)="register_pages='page_2'"
class="btn btn-info btn-lg btn-block text-uppercase waves-effect waves-light"
[disabled]="!form.controls['name'].valid ||
!form.controls['last_name1'].valid ||
!form.controls['last_name2'].valid ||
!form.controls['rut'].valid">
<button type="button" (click)="nextPage('page_2')"
class="btn btn-info btn-lg btn-block text-uppercase waves-effect waves-light">
Continuar
</button>
</div>
Expand Down Expand Up @@ -98,12 +94,14 @@ <h3 class="box-title m-t-40 m-b-0">Categorías de interés <span>(Min. 3)</span>
</select>
</div>
</div>
<p *ngIf="selected_categories.length < 3 && submit2" class="text-danger">
Debe seleccionar al menos 3 categorias
</p>

<div class="form-group text-center m-t-20">
<div class="col-xs-12">
<button (click)="register_pages='page_3'"
class="btn btn-info btn-lg btn-block text-uppercase waves-effect waves-light"
[disabled]="selected_categories.length < 3">
<button type="button" (click)="nextPage('page_3')"
class="btn btn-info btn-lg btn-block text-uppercase waves-effect waves-light">
Continuar
</button>
</div>
Expand Down Expand Up @@ -133,8 +131,8 @@ <h3 class="box-title m-t-40 m-b-0">Datos de la cuenta</h3>
<div class="col-xs-12">
<input formControlName="email" class="form-control" type="text" placeholder="Correo electrónico">
</div>
<div *ngIf="form.controls['email'].errors?.required && submit"><p class="text-danger">El email es requerido</p></div>
<div *ngIf="form.controls['email'].errors?.email && submit"><p class="text-danger">El email ingresado no es válido</p></div>
<div *ngIf="form.controls['email'].errors?.required && submit3"><p class="text-danger">El email es requerido</p></div>
<div *ngIf="form.controls['email'].errors?.email && submit3"><p class="text-danger">El email ingresado no es válido</p></div>
</div>

<div class="form-group ">
Expand All @@ -149,7 +147,7 @@ <h3 class="box-title m-t-40 m-b-0">Datos de la cuenta</h3>
</div>
</div>

<div class="form-group" *ngIf="form['errors']?.areEquals && !form.pristine && submit">
<div class="form-group" *ngIf="form['errors']?.areEquals && !form.pristine && submit3">
<p class="text-danger"> Las contraseñas deben ser iguales </p>
</div>

Expand All @@ -168,8 +166,7 @@ <h3 class="box-title m-t-40 m-b-0">Datos de la cuenta</h3>
<div class="form-group text-center m-t-20">
<div class="col-xs-12">
<button class="btn btn-info btn-lg btn-block text-uppercase waves-effect waves-light"
type="submit"
[disabled]="!form.controls['email'].valid || !form.controls['password'].valid || !form.controls['password2'].valid">
type="submit">
Registrarme
</button>
</div>
Expand Down
26 changes: 22 additions & 4 deletions src/app/register/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export class RegisterComponent implements OnInit {
register_pages:string = "page_1"; //Muestra la primera página del registro por defecto
categories:any[] = CATEGORIES;
selected_categories:any[] = [];
submit:boolean = false;
submit1:boolean = false;
submit2:boolean = false;
submit3:boolean = false;

constructor( private _dbService:DatabaseService,
private _dateService:DateService,
Expand Down Expand Up @@ -76,9 +78,9 @@ export class RegisterComponent implements OnInit {
// Guarda un usuario nuevo, en DB
saveUser(){

this.submit = true;

console.log(this.form);
this.submit1 = true;
this.submit2 = true;
this.submit3 = true;

if (this.form.valid) {
let form=this.form.value;
Expand Down Expand Up @@ -158,6 +160,22 @@ export class RegisterComponent implements OnInit {
this.selected_categories.splice(index, 1);
}


nextPage(page:string){
let form = this.form;
switch( page ) {
case 'page_2':
this.submit1 = true;
if( form.controls['name'].valid && form.controls['last_name1'].valid && form.controls['last_name2'].valid && form.controls['rut'].valid)
this.register_pages = 'page_2';
break;
case 'page_3':
this.submit2 = true;
if( this.selected_categories.length >= 3 )
this.register_pages = 'page_3';
break;
}
}
// Cambia el fondo del register dependiendo de en qué etapa se encuentre
getBackground(page:string) {
switch (page) {
Expand Down

0 comments on commit 88fa0ae

Please sign in to comment.