2016-06-16 11:47:25 +03:00
|
|
|
import {Component, ViewEncapsulation} from '@angular/core';
|
2016-07-08 13:10:36 +03:00
|
|
|
import {FormGroup, AbstractControl, FormBuilder, Validators} from '@angular/forms';
|
2016-06-16 12:50:49 +03:00
|
|
|
import {EmailValidator, EqualPasswordsValidator} from '../../theme/validators';
|
2016-06-16 11:47:25 +03:00
|
|
|
|
|
|
|
|
@Component({
|
2016-06-16 12:50:49 +03:00
|
|
|
selector: 'register',
|
2016-06-16 11:47:25 +03:00
|
|
|
encapsulation: ViewEncapsulation.None,
|
|
|
|
|
styles: [require('./register.scss')],
|
|
|
|
|
template: require('./register.html'),
|
|
|
|
|
})
|
|
|
|
|
export class Register {
|
|
|
|
|
|
2016-07-08 13:10:36 +03:00
|
|
|
public form:FormGroup;
|
2016-06-16 12:50:49 +03:00
|
|
|
public name:AbstractControl;
|
|
|
|
|
public email:AbstractControl;
|
|
|
|
|
public password:AbstractControl;
|
|
|
|
|
public repeatPassword:AbstractControl;
|
2016-07-08 13:10:36 +03:00
|
|
|
public passwords:FormGroup;
|
2016-06-16 12:50:49 +03:00
|
|
|
|
|
|
|
|
public submitted:boolean = false;
|
|
|
|
|
|
|
|
|
|
constructor(fb:FormBuilder) {
|
|
|
|
|
|
|
|
|
|
this.form = fb.group({
|
|
|
|
|
'name': ['', Validators.compose([Validators.required, Validators.minLength(4)])],
|
|
|
|
|
'email': ['', Validators.compose([Validators.required, EmailValidator.validate])],
|
|
|
|
|
'passwords': fb.group({
|
|
|
|
|
'password': ['', Validators.compose([Validators.required, Validators.minLength(4)])],
|
|
|
|
|
'repeatPassword': ['', Validators.compose([Validators.required, Validators.minLength(4)])]
|
|
|
|
|
}, {validator: EqualPasswordsValidator.validate('password', 'repeatPassword')})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.name = this.form.controls['name'];
|
|
|
|
|
this.email = this.form.controls['email'];
|
2016-07-08 13:10:36 +03:00
|
|
|
this.passwords = <FormGroup> this.form.controls['passwords'];
|
2016-06-16 12:50:49 +03:00
|
|
|
this.password = this.passwords.controls['password'];
|
|
|
|
|
this.repeatPassword = this.passwords.controls['repeatPassword'];
|
2016-06-16 11:47:25 +03:00
|
|
|
}
|
|
|
|
|
|
2016-06-16 12:50:49 +03:00
|
|
|
public onSubmit(values:Object):void {
|
|
|
|
|
this.submitted = true;
|
|
|
|
|
if (this.form.valid) {
|
|
|
|
|
// your code goes here
|
|
|
|
|
// console.log(values);
|
|
|
|
|
}
|
2016-06-16 11:47:25 +03:00
|
|
|
}
|
|
|
|
|
}
|