mirror of
https://github.com/akveo/ngx-admin.git
synced 2026-02-24 08:54:06 +01:00
feat(register): add angular 2 form logic
This commit is contained in:
parent
2ba18109cd
commit
1a2512daaf
6 changed files with 84 additions and 15 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import {Component, ViewEncapsulation} from '@angular/core';
|
||||
|
||||
import {FORM_DIRECTIVES, FormBuilder, ControlGroup, Validators, AbstractControl} from '@angular/common';
|
||||
import {EmailValidator, EqualPasswordsValidator} from '../../theme/validators';
|
||||
|
||||
@Component({
|
||||
selector: 'login',
|
||||
selector: 'register',
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
directives: [],
|
||||
styles: [require('./register.scss')],
|
||||
|
|
@ -10,9 +11,38 @@ import {Component, ViewEncapsulation} from '@angular/core';
|
|||
})
|
||||
export class Register {
|
||||
|
||||
constructor() {
|
||||
public form:ControlGroup;
|
||||
public name:AbstractControl;
|
||||
public email:AbstractControl;
|
||||
public password:AbstractControl;
|
||||
public repeatPassword:AbstractControl;
|
||||
public passwords:ControlGroup;
|
||||
|
||||
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'];
|
||||
this.passwords = <ControlGroup> this.form.controls['passwords'];
|
||||
this.password = this.passwords.controls['password'];
|
||||
this.repeatPassword = this.passwords.controls['repeatPassword'];
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
public onSubmit(values:Object):void {
|
||||
this.submitted = true;
|
||||
if (this.form.valid) {
|
||||
// your code goes here
|
||||
// console.log(values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue