From 4837b847ea8e26ac5a445b030fbf42831a3e64d0 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Tue, 28 Mar 2017 18:33:26 +0200 Subject: [PATCH 1/2] Add validation on the owner add page --- .../owners/owner-add/owner-add.component.html | 73 +++++++++++-------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/src/app/owners/owner-add/owner-add.component.html b/src/app/owners/owner-add/owner-add.component.html index 76977e34..49af1cd4 100644 --- a/src/app/owners/owner-add/owner-add.component.html +++ b/src/app/owners/owner-add/owner-add.component.html @@ -22,46 +22,57 @@

New Owner

-
- -
- -
- -
+ +
+ +
+ + + First name is required + First name must be at least 2 characters long
-
- -
- -
+
+
+ +
+ + + Last name is required + Last name must be at least 2 characters long
-
- -
- -
+
+
+ +
+ + + Address is required
-
- -
- -
+
+
+ +
+ + + City is required
-
- -
- -
+
+
+ +
+ + + Phone number is required + Phone number cannot be more than 10 digits long + Phone number only accept digits
-
- +
From 26310ca7e1f21963c7942dafdb40a7d96dbf7126 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Tue, 28 Mar 2017 18:41:41 +0200 Subject: [PATCH 2/2] After save or update, redirect user to the owner detail page --- src/app/owners/owner-add/owner-add.component.ts | 5 ++--- src/app/owners/owner-edit/owner-edit.component.ts | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app/owners/owner-add/owner-add.component.ts b/src/app/owners/owner-add/owner-add.component.ts index f76ee9cb..b35b0020 100644 --- a/src/app/owners/owner-add/owner-add.component.ts +++ b/src/app/owners/owner-add/owner-add.component.ts @@ -34,7 +34,6 @@ export class OwnerAddComponent implements OnInit { owner: Owner; errorMessage: string; - added_success: boolean = false; constructor(private ownerService: OwnerService, private router: Router) { this.owner = {}; @@ -47,8 +46,8 @@ export class OwnerAddComponent implements OnInit { owner.id = null; this.ownerService.addOwner(owner).subscribe( new_owner => { - this.added_success = true; - return this.owner = new_owner; + this.owner = new_owner; + this.gotoOwnersList(); }, error => this.errorMessage = error ); diff --git a/src/app/owners/owner-edit/owner-edit.component.ts b/src/app/owners/owner-edit/owner-edit.component.ts index 2aecfec3..1097e60f 100644 --- a/src/app/owners/owner-edit/owner-edit.component.ts +++ b/src/app/owners/owner-edit/owner-edit.component.ts @@ -47,6 +47,7 @@ export class OwnerEditComponent implements OnInit { } onSubmit(owner) { + var that = this; this.ownerService.updateOwner(owner.id.toString(), owner).subscribe( get_result, get_error @@ -61,7 +62,8 @@ export class OwnerEditComponent implements OnInit { function get_result(update_status) { console.log(update_status); if (update_status.status === 204) { - return console.log('update success'); + console.log('update success'); + that.gotoOwnerDetail(owner); } else { return console.log('update failed'); } @@ -72,4 +74,6 @@ export class OwnerEditComponent implements OnInit { this.router.navigate(['/owners', owner.id]); } + + }