Skip to content

Commit 0b8658f

Browse files
Dan WahlinDan Wahlin
Dan Wahlin
authored and
Dan Wahlin
committed
Added reactive form
1 parent 14f964d commit 0b8658f

18 files changed

+452
-22
lines changed

src/.vscode/settings.json renamed to .vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Place your settings in this file to overwrite default and user settings.
22
{
33
"files.exclude": {
4-
"**/app/**/*.js.map": true,
5-
"**/app/**/*.js": true
4+
"src/public/app/**/*.js.map": true,
5+
"src/public/app/**/*.js": true
66
}
77
,
88
"typescript.tsdk": "./node_modules/typescript/lib"

src/public/app/app.routing.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/app/app.routing.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/app/app.routing.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ import { RouterModule, Routes } from '@angular/router';
33
import { CustomersComponent } from './customers/customers.component';
44
import { CustomersGridComponent } from './customers/customers-grid.component';
55
import { CustomerEditComponent } from './customers/customer-edit.component';
6+
import { CustomerEditReactiveComponent } from './customers/customer-edit-reactive.component';
67
import { IRouting } from './shared/interfaces';
78

89
const routes: Routes = [
910
{ path: 'customers', component: CustomersComponent},
10-
{ path: 'customers/:id', component: CustomerEditComponent},
11+
//{ path: 'customers/:id', component: CustomerEditComponent},
12+
{ path: 'customers/:id', component: CustomerEditReactiveComponent },
1113
{ path: '**', pathMatch:'full', redirectTo: '/customers' } //catch any unfound routes and redirect to home page
1214
];
1315

1416
export const appRouting: IRouting = {
1517
routes: RouterModule.forRoot(routes),
16-
components: [ CustomersComponent, CustomerEditComponent, CustomersGridComponent ]
18+
components: [ CustomersComponent, CustomerEditComponent, CustomerEditReactiveComponent, CustomersGridComponent ]
1719
};
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<div>
2+
<header>
3+
<h3>
4+
<span class="glyphicon glyphicon-user"></span>
5+
{{ customer.firstName }} {{ customer.lastName }}
6+
</h3>
7+
</header>
8+
<br />
9+
<form [formGroup]="customerForm" (ngSubmit)="submit(customerForm)" class="editForm" novalidate>
10+
<div class="form-group">
11+
<label>Name</label>
12+
<input type="text" class="form-control" formControlName="firstName" />
13+
<div class="alert alert-danger" [hidden]="customerForm.controls.firstName.untouched || customerForm.controls.firstName.valid">First Name is required</div>
14+
</div>
15+
<div class="form-group">
16+
<label>Last Name</label>
17+
<input type="text" class="form-control" formControlName="lastName">
18+
<div class="alert alert-danger" [hidden]="customerForm.controls.lastName.untouched || customerForm.controls.lastName.valid">Last Name is required</div>
19+
</div>
20+
<div class="form-group">
21+
<label>Gender</label>
22+
<br />
23+
<div class="radio">
24+
<label>
25+
<input type="radio" name="gender" formControlName="gender" value="Male" />
26+
Male
27+
</label>
28+
</div>
29+
<div class="radio">
30+
<label>
31+
<input type="radio" name="gender" formControlName="gender" value="Female" />
32+
Female
33+
</label>
34+
</div>
35+
</div>
36+
<div class="form-group">
37+
<label>Email</label>
38+
<input type="email" class="form-control" formControlName="email" />
39+
<div class="alert alert-danger" [hidden]="customerForm.controls.email.untouched || customerForm.controls.email.valid">Email is required and must be valid</div>
40+
</div>
41+
<div class="form-group">
42+
<label>Address</label>
43+
<input type="text" class="form-control" formControlName="address" />
44+
<div class="alert alert-danger" [hidden]="customerForm.controls.address.untouched || customerForm.controls.address.valid">Address is required</div>
45+
</div>
46+
<div class="form-group">
47+
<label>City</label>
48+
<input type="text" class="form-control" formControlName="city" />
49+
<div class="alert alert-danger" [hidden]="customerForm.controls.city.untouched || customerForm.controls.city.valid">City is required</div>
50+
</div>
51+
<div class="form-group">
52+
<label>State</label>
53+
<select class="form-control" formControlName="stateId">
54+
<option *ngFor="let state of states" [ngValue]="state.id">{{state.name}}</option>
55+
</select>
56+
</div>
57+
<br />
58+
59+
<div *ngIf="customer">
60+
<div class="alert alert-warning" *ngIf="customer._id && deleteMessageEnabled">
61+
Delete Customer?&nbsp;&nbsp;<button class="btn btn-danger" (click)="delete($event)">Yes</button>&nbsp;&nbsp;
62+
<button class="btn btn-default" (click)="deleteMessageEnabled = false">No</button>
63+
</div>
64+
<button class="btn btn-danger" *ngIf="customer._id && !deleteMessageEnabled" (click)="deleteMessageEnabled = true">Delete</button>&nbsp;&nbsp;
65+
66+
<div class="pull-right" *ngIf="!deleteMessageEnabled">
67+
<button class="btn btn-default" (click)="cancel($event)">Cancel</button>&nbsp;&nbsp;
68+
<button type="submit" class="btn btn-success" [disabled]="!customerForm.valid">{{ operationText }}</button>
69+
</div>
70+
</div>
71+
<br />
72+
<br />
73+
<div class="alert alert-danger" *ngIf="errorMessage != null">{{ errorMessage }}</div>
74+
75+
</form>
76+
</div>

src/public/app/customers/customer-edit-reactive.component.js

Lines changed: 128 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/app/customers/customer-edit-reactive.component.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)