From d8ff4064e204308300e7b86cc7de0a0988aed9c6 Mon Sep 17 00:00:00 2001 From: piratefinn Date: Mon, 5 Jun 2017 15:22:51 +0100 Subject: [PATCH] Proper Working Validation added Still needs visual validation --- src/app/pages/register.component.html | 12 ++-- src/app/pages/register.component.ts | 83 ++++++++++++++++++++++----- 2 files changed, 75 insertions(+), 20 deletions(-) diff --git a/src/app/pages/register.component.html b/src/app/pages/register.component.html index d6bfc6f..d14d194 100644 --- a/src/app/pages/register.component.html +++ b/src/app/pages/register.component.html @@ -15,7 +15,7 @@ --> -
+
@@ -46,9 +46,9 @@
-
+
-
+
@@ -75,15 +75,15 @@
-
+
- +
- +
diff --git a/src/app/pages/register.component.ts b/src/app/pages/register.component.ts index 7b85219..9cd0389 100644 --- a/src/app/pages/register.component.ts +++ b/src/app/pages/register.component.ts @@ -12,7 +12,9 @@ import 'rxjs/add/operator/map'; }) export class RegisterComponent { - signup: ValidationManager; + signupForm: ValidationManager; + customerForm: ValidationManager; + organisationForm: ValidationManager; ageRanges: Object[]; constructor( @@ -28,30 +30,83 @@ export class RegisterComponent { this.ageRanges = result.ages; } ); - this.signup = new ValidationManager({ + this.signupForm = new ValidationManager({ token: 'required', usertype: 'required', - name: 'required', - full_name: 'required', - display_name: 'required', email: 'required', - postcode: 'required', - street_name: 'required', - town: 'required', - age_range: 'required', password: 'required', confirmpassword: 'required|equalTo:password' }); + this.customerForm = new ValidationManager({ + display_name: 'required', + full_name: 'required', + postcode: 'required', + age_range: 'required', + }); + this.organisationForm = new ValidationManager({ + name: 'required', + street_name: 'required', + town: 'required', + postcode: 'required', + }); } - onSubmit() { + onSubmitCustomer() { - console.log(this.signup.isValid()); - - console.log(this.signup.getForm().value); + console.log(this.signupForm.isValid()); + if (!this.signupForm.isValid() && !this.customerForm.isValid()) { + console.log("Not Valid!"); + return; + } + let signupForm = this.signupForm.getForm().value; + let customerForm = this.customerForm.getForm().value; + let data = { + token: signupForm.token, + usertype: signupForm.usertype, + email: signupForm.email, + password: signupForm.password, + display_name: customerForm.display_name, + full_name: customerForm.full_name, + postcode: customerForm.postcode, + age_range: customerForm.age_range, + }; + console.log(data); /* this.api - .register(this.signup.value) + .register(data) + .subscribe( + result => { + console.log('registered!'); + this.router.navigate(['/dashboard']); + }, + error => { + console.log( error._body ); + } + );*/ + } + onSubmitOrganisation() { + + console.log(this.signupForm.isValid()); + if (!this.signupForm.isValid() || !this.organisationForm.isValid()) { + console.log("Not Valid!"); + return; + } + let signupForm = this.signupForm.getForm().value; + let organisationForm = this.organisationForm.getForm().value; + + let data = { + token: signupForm.token, + usertype: signupForm.usertype, + email: signupForm.email, + password: signupForm.password, + name: organisationForm.name, + street_name: organisationForm.street_name, + town: organisationForm.town, + postcode: organisationForm.postcode, + }; + console.log(data); + /* this.api + .register(data) .subscribe( result => { console.log('registered!');