signup
This commit is contained in:
parent
5809b605b1
commit
d5140adfca
|
@ -7,29 +7,57 @@
|
|||
<div class="ui-g-12">
|
||||
<span class="md-inputfield">
|
||||
<input id="email" type="email" pInputText class="input ng-dirty ng-invalid" placeholder="Email" formControlName="email" required>
|
||||
<div *ngIf="signupForm.get('email').touched && signupForm.get('email').errors" class="ui-message ui-messages-error ui-corner-all">
|
||||
Not valid email
|
||||
<div *ngIf="email.touched && !email.valid" class="ui-message ui-messages-error ui-corner-all">
|
||||
Invalid email
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
<div class="ui-g-12">
|
||||
<span class="md-inputfield">
|
||||
<input id="password" type="password" pInputText class="input ng-dirty ng-invalid" placeholder="Password" formControlName="password"
|
||||
required #passwsord="ngModel">
|
||||
<div #password *ngIf="signupForm.get('password').touched && signupForm.get('password').errors" class="ui-message ui-messages-error ui-corner-all">
|
||||
Not valid password
|
||||
required>
|
||||
<div *ngIf="password.touched && !password.valid" class="ui-message ui-messages-error ui-corner-all">
|
||||
Invalid password
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
<div class="ui-g-12">
|
||||
<span class="md-inputfield">
|
||||
<input id="pwConfirm" type="password" pInputText class="input ng-dirty ng-invalid" placeholder="Retype your password" formControlName="pwConfirm"
|
||||
required validateEqual="password" #confirmPassword="ngModel">
|
||||
<div *ngIf="pwConfirm.valid || (confirmPassword.pristine && !f.submitted)" class="ui-message ui-messages-error ui-corner-all">
|
||||
required>
|
||||
<div *ngIf="pwConfirm.touched && !pwConfirm.valid" class="ui-message ui-messages-error ui-corner-all">
|
||||
Not matched password
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="ui-g-12">
|
||||
<span class="md-inputfield">
|
||||
<input id="name" type="text" pInputText class="input ng-dirty ng-invalid" placeholder="Name" formControlName="name" required>
|
||||
<div *ngIf="name.touched && !name.valid" class="ui-message ui-messages-error ui-corner-all">
|
||||
Invalid Name
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="ui-g-12">
|
||||
<span class="md-inputfield">
|
||||
<input id="phone" type="text" pInputText class="input ng-dirty ng-invalid" placeholder="Phone" formControlName="phone" required>
|
||||
<div *ngIf="phone.touched && !phone.valid" class="ui-message ui-messages-error ui-corner-all">
|
||||
Invalid phone number
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="ui-g-12">
|
||||
<span class="md-inputfield">
|
||||
<input id="company" type="text" pInputText class="input ng-dirty ng-invalid" placeholder="Company" formControlName="company" required>
|
||||
<div *ngIf="company.touched && !company.valid" class="ui-message ui-messages-error ui-corner-all">
|
||||
Invalid company name
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="ui-g-12">
|
||||
<button type="submit" [disabled]="!signupForm.valid" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left">
|
||||
<span class="ui-button-icon-left ui-c fa fa-fw ui-icon-person"></span>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { FormGroup, FormBuilder, Validators, AbstractControl } from '@angular/forms';
|
||||
import { Member } from '@loafer/core/reflect';
|
||||
import { FormGroup, FormBuilder, Validators, AbstractControl, FormControl } from '@angular/forms';
|
||||
import { Member } from '../../model';
|
||||
|
||||
@Component({
|
||||
selector: 'of-member-signup',
|
||||
|
@ -11,15 +11,12 @@ import { Member } from '@loafer/core/reflect';
|
|||
export class SignupComponent implements OnInit {
|
||||
|
||||
signupForm: FormGroup;
|
||||
formErrors = {
|
||||
'email': '',
|
||||
'password': '',
|
||||
'pwConfirm': '',
|
||||
'name': '',
|
||||
'phone': '',
|
||||
'company': ''
|
||||
};
|
||||
member: Member;
|
||||
email: AbstractControl;
|
||||
password: AbstractControl;
|
||||
pwConfirm: AbstractControl;
|
||||
name: AbstractControl;
|
||||
phone: AbstractControl;
|
||||
company: AbstractControl;
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
|
@ -45,7 +42,9 @@ export class SignupComponent implements OnInit {
|
|||
]
|
||||
],
|
||||
'pwConfirm': ['', [
|
||||
Validators.required,
|
||||
Validators.compose([
|
||||
Validators.required, this.pwMatchValidator
|
||||
])
|
||||
]
|
||||
],
|
||||
'name': ['', [
|
||||
|
@ -60,17 +59,35 @@ export class SignupComponent implements OnInit {
|
|||
Validators.required
|
||||
]
|
||||
],
|
||||
}, this.pwdMatchValidator);
|
||||
});
|
||||
this.email = this.signupForm.controls['email'];
|
||||
this.password = this.signupForm.controls['password'];
|
||||
this.pwConfirm = this.signupForm.controls['pwConfirm'];
|
||||
this.name = this.signupForm.controls['name'];
|
||||
this.phone = this.signupForm.controls['phone'];
|
||||
this.company = this.signupForm.controls['company'];
|
||||
}
|
||||
|
||||
pwdMatchValidator(frm: FormGroup) {
|
||||
return frm.get('password').value === frm.get('pwConfirm').value
|
||||
? null : {'mismatch': true};
|
||||
}
|
||||
pwMatchValidator(control: FormControl): { [s: string]: boolean } {
|
||||
let pw;
|
||||
if (control.parent) {
|
||||
pw = control.parent.controls['password'].value;
|
||||
}
|
||||
if (control.value !== pw) {
|
||||
return { notMatched: true };
|
||||
}
|
||||
}
|
||||
|
||||
signup() {
|
||||
const signinValue = Object.assign({}, this.signupForm.value);
|
||||
console.log(signinValue);
|
||||
const member: Member = {
|
||||
email: signinValue.email,
|
||||
password: signinValue.password,
|
||||
name: signinValue.name,
|
||||
phone: signinValue.phone,
|
||||
companyName: signinValue.company,
|
||||
};
|
||||
console.log(member);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user