Skip to content

Commit 407355c

Browse files
committed
chore(reactive-form): add dev sample for reactive form
1 parent 63acbaf commit 407355c

File tree

6 files changed

+125
-1
lines changed

6 files changed

+125
-1
lines changed

src/app/app.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ export class AppComponent implements OnInit {
332332
icon: 'radio_button_checked',
333333
name: 'Radio Group'
334334
},
335+
{
336+
link: '/reactive',
337+
icon: 'web',
338+
name: 'Reactive Form'
339+
},
335340
{
336341
link: '/select',
337342
icon: 'arrow_drop_down_circle',

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ import { GridExternalFilteringComponent } from './grid-external-filtering/grid-e
115115
import { AboutComponent } from './grid-state/about.component';
116116
import { GridSaveStateComponent } from './grid-state/grid-state.component';
117117
import { GridMasterDetailSampleComponent } from './grid-master-detail/grid-master-detail.sample';
118+
import { ReactiveFormSampleComponent } from './reactive-from/reactive-form-sample.component';
118119

119120
const components = [
120121
AppComponent,
@@ -220,7 +221,8 @@ const components = [
220221
GridFilteringComponent,
221222
GridExternalFilteringComponent,
222223
GridSaveStateComponent,
223-
AboutComponent
224+
AboutComponent,
225+
ReactiveFormSampleComponent
224226
];
225227

226228
@NgModule({
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<div class="sample-wrapper">
2+
<section class="sample-content">
3+
<article class="sample-column">
4+
<form class="input-group-form" [formGroup]="user" (ngSubmit)="onSubmit()">
5+
<h4 class="sample-title">Book your movie ticket</h4>
6+
<div class="container">
7+
<igx-select #select name="movies" formControlName="movie">
8+
<igx-select-item-group *ngFor="let genre of genres" [label]="genre.type">
9+
<igx-select-item *ngFor="let movie of genre.movies" [value]="movie">
10+
{{ movie }}
11+
</igx-select-item>
12+
</igx-select-item-group>
13+
<label igxLabel for="movies">Movie</label>
14+
<ng-template igxSelectToggleIcon><igx-icon fontSet="material">local_movies</igx-icon></ng-template>
15+
</igx-select>
16+
<igx-input-group>
17+
<input igxInput name="fullName" type="text" formControlName="fullName" />
18+
<label igxLabel for="fullName">Full Name</label>
19+
<igx-suffix>
20+
<igx-icon>person</igx-icon>
21+
</igx-suffix>
22+
</igx-input-group>
23+
<igx-input-group>
24+
<igx-prefix>+359</igx-prefix>
25+
<label igxLabel for="phone">Phone</label>
26+
<input igxInput name="phone" type="text" formControlName="phone" />
27+
<igx-suffix>
28+
<igx-icon>phone</igx-icon>
29+
</igx-suffix>
30+
<igx-hint position="start">Ex.: +359 888 123 456</igx-hint>
31+
</igx-input-group>
32+
<igx-input-group>
33+
<label igxLabel for="email">Email address</label>
34+
<input igxInput name="email" type="email" formControlName="email" />
35+
<igx-suffix>
36+
<igx-icon>email</igx-icon>
37+
</igx-suffix>
38+
</igx-input-group>
39+
<igx-combo #combo1 class="input-container" [itemsMaxHeight]="130"
40+
[data]="genres" [valueKey]="'type'" [displayKey]="'type'"
41+
type="line" formControlName="genres" placeholder="Select your favorite genres"
42+
searchPlaceholder="Search...">
43+
</igx-combo>
44+
<igx-date-picker name="date" formControlName="date" [mode]="'dropdown'"></igx-date-picker>
45+
<igx-time-picker name="dateTime" formControlName="dateTime"></igx-time-picker>
46+
<button igxButton="raised" igxRipple type="submit" [disabled]="!user.valid">Book</button>
47+
</div>
48+
</form>
49+
</article>
50+
</section>
51+
</div>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.container > * {
2+
margin-top: 32px;
3+
}
4+
5+
.input-group-form {
6+
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.2), 0 1px 1px 0 rgba(0, 0, 0, 0.14), 0 2px 1px -1px rgba(0, 0, 0, 0.12);
7+
padding: 24px;
8+
margin-bottom: 48px;
9+
}
10+
11+
.sample-title {
12+
margin-top: 0;
13+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Component } from '@angular/core';
2+
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
3+
4+
@Component({
5+
selector: 'app-reactive-form',
6+
styleUrls: ['reactive-form-sample.component.scss'],
7+
templateUrl: 'reactive-form-sample.component.html'
8+
})
9+
export class ReactiveFormSampleComponent {
10+
public genres = [];
11+
public user: FormGroup;
12+
13+
constructor(fb: FormBuilder) {
14+
this.user = fb.group({
15+
// date: ['', Validators.required],
16+
date: ['', { validators: Validators.required, updateOn: 'blur' }],
17+
dateTime: ['', Validators.required],
18+
email: ['', Validators.required],
19+
fullName: new FormControl('', Validators.required),
20+
genres: [''],
21+
movie: ['', Validators.required],
22+
phone: ['']
23+
});
24+
25+
this.genres = [
26+
{ type: 'Action', movies: ['The Matrix', 'Kill Bill: Vol.1', 'The Dark Knight Rises'] },
27+
{ type: 'Adventure', movies: ['Interstellar', 'Inglourious Basterds', 'Inception'] },
28+
// tslint:disable-next-line:object-literal-sort-keys
29+
{
30+
type: 'Comedy', movies: ['Wild Tales', 'In Bruges', 'Three Billboards Outside Ebbing, Missouri',
31+
'Untouchable', '3 idiots']
32+
},
33+
{ type: 'Crime', movies: ['Training Day', 'Heat', 'American Gangster'] },
34+
{ type: 'Drama', movies: ['Fight Club', 'A Beautiful Mind', 'Good Will Hunting', 'City of God'] },
35+
{ type: 'Biography', movies: ['Amadeus', 'Bohemian Rhapsody'] },
36+
{ type: 'Mystery', movies: ['The Prestige', 'Memento', 'Cloud Atlas'] },
37+
{ type: 'Musical', movies: ['All That Jazz'] },
38+
{ type: 'Romance', movies: ['Love Actually', 'In The Mood for Love'] },
39+
{ type: 'Sci-Fi', movies: ['The Fifth Element'] },
40+
{ type: 'Thriller', movies: ['The Usual Suspects'] },
41+
{ type: 'Western', movies: ['Django Unchained'] }];
42+
43+
}
44+
45+
public onSubmit() {
46+
console.log(this.user);
47+
}
48+
}

src/app/routing.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ import { GridExternalFilteringComponent } from './grid-external-filtering/grid-e
9292
import { GridSaveStateComponent } from './grid-state/grid-state.component';
9393
import { AboutComponent } from './grid-state/about.component';
9494
import { GridMasterDetailSampleComponent } from './grid-master-detail/grid-master-detail.sample';
95+
import { ReactiveFormSampleComponent } from './reactive-from/reactive-form-sample.component';
9596

9697
const appRoutes = [
9798
{
@@ -235,6 +236,10 @@ const appRoutes = [
235236
path: 'radio',
236237
component: RadioSampleComponent
237238
},
239+
{
240+
path: 'reactive',
241+
component: ReactiveFormSampleComponent
242+
},
238243
{
239244
path: 'ripple',
240245
component: RippleSampleComponent

0 commit comments

Comments
 (0)