Skip to content

Commit d417dfe

Browse files
author
Konstantin Dinev
authored
Merge pull request #2703 from IgniteUI/PMiteva/date-time-picker-samples-master
Create date & time picker form samples-master
2 parents 66ae929 + fa92ee4 commit d417dfe

10 files changed

Lines changed: 154 additions & 1 deletion

live-editing/configs/DatePickerConfigGenerator.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import {ReactiveFormsModule} from '@angular/forms';
12
import {IgxAutocompleteModule,
23
IgxButtonModule,
34
IgxCalendarModule,
45
IgxDatePickerModule,
6+
IgxTimePickerModule,
57
IgxDropDownModule,
68
IgxIconModule,
79
IgxInputGroupModule,
@@ -118,6 +120,26 @@ export class DatePickerConfigGenerator implements IConfigGenerator {
118120
})
119121
}));
120122

123+
// date & time picker - template driven form
124+
configs.push(new Config({
125+
component: 'DateTimePickerTDFSampleComponent',
126+
appModuleConfig: new AppModuleConfig({
127+
imports: ['DateTimePickerTDFSampleComponent', 'IgxDatePickerModule', 'IgxTimePickerModule'],
128+
ngDeclarations: ['DateTimePickerTDFSampleComponent'],
129+
ngImports: ['IgxDatePickerModule', 'IgxTimePickerModule']
130+
})
131+
}));
132+
133+
// date & time picker - reactive form
134+
configs.push(new Config({
135+
component: 'DateTimePickerRFSampleComponent',
136+
appModuleConfig: new AppModuleConfig({
137+
imports: ['DateTimePickerRFSampleComponent', 'IgxDatePickerModule', 'IgxTimePickerModule', 'ReactiveFormsModule'],
138+
ngDeclarations: ['DateTimePickerRFSampleComponent'],
139+
ngImports: ['IgxDatePickerModule', 'IgxTimePickerModule', 'ReactiveFormsModule']
140+
})
141+
}));
142+
121143
return configs;
122144
}
123145
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<div class="pickers-wrapper">
2+
<form [formGroup]="dateTimeForm">
3+
<div class="form-group">
4+
<div class="form-date-picker">
5+
<igx-date-picker #datePicker formControlName="date" [value]="date" [minValue]="minDate"
6+
[maxValue]="maxDate" (valueChange)="timePicker.value = datePicker.value">
7+
<label igxLabel>Date</label>
8+
</igx-date-picker>
9+
</div>
10+
<div class="form-time-picker">
11+
<igx-time-picker #timePicker formControlName="time" [value]="date" [minValue]="minTime"
12+
[maxValue]="maxTime" [disabled]="dateTimeForm.value.date ? false : true"
13+
(valueChange)="datePicker.value = timePicker.value">
14+
<label igxLabel>Time</label>
15+
</igx-time-picker>
16+
</div>
17+
</div>
18+
</form>
19+
<p>
20+
Date picker: {{ dateTimeForm.value.date? dateTimeForm.value.date.toLocaleString() : null}}<br>
21+
Time picker: {{ dateTimeForm.value.time? dateTimeForm.value.time.toLocaleString() : null}}<br>
22+
Form Status: {{ dateTimeForm.status }}
23+
</p>
24+
</div>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.pickers-wrapper {
2+
display: flex;
3+
flex-direction: column;
4+
}
5+
6+
.form-group {
7+
display: flex;
8+
flex: 1;
9+
width: 400px;
10+
}
11+
12+
.form-date-picker {
13+
flex: 55%;
14+
}
15+
16+
.form-time-picker {
17+
flex: 45%;
18+
margin-left: 16px;
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Component } from '@angular/core';
2+
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3+
4+
@Component({
5+
selector: 'app-datetimepicker-reactive-form',
6+
styleUrls: ['./reactive-form.component.scss'],
7+
templateUrl: './reactive-form.component.html'
8+
})
9+
export class DateTimePickerRFSampleComponent {
10+
public dateTimeForm: FormGroup;
11+
public date = new Date(2021, 6, 12, 7, 30, 0);
12+
public minDate = new Date(this.date.getFullYear(), this.date.getMonth(), this.date.getDate() - 10);
13+
public maxDate = new Date(this.date.getFullYear(), this.date.getMonth(), this.date.getDate() + 15);
14+
public minTime = '06:15:30';
15+
public maxTime = '15:15:30';
16+
17+
constructor(fb: FormBuilder) {
18+
this.dateTimeForm = fb.group({
19+
date: [this.date, Validators.required],
20+
time: [this.date, Validators.required]
21+
});
22+
}
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div class="pickers-wrapper">
2+
<div class="form-group">
3+
<div class="form-date-picker">
4+
<igx-date-picker #datePicker name="date-picker" [(ngModel)]="date">
5+
<label igxLabel>Date</label>
6+
</igx-date-picker>
7+
</div>
8+
<div class="form-time-picker">
9+
<igx-time-picker name="time-picker" [(ngModel)]="date" [disabled]="datePicker.value ? false : true">
10+
<label igxLabel>Time</label>
11+
</igx-time-picker>
12+
</div>
13+
</div>
14+
<p class="text">
15+
Selected date: {{ date? date.toLocaleString() : null }}
16+
</p>
17+
</div>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.pickers-wrapper {
2+
display: flex;
3+
flex-direction: column;
4+
}
5+
6+
.form-group {
7+
display: flex;
8+
flex: 1;
9+
width: 400px;
10+
}
11+
12+
.form-date-picker {
13+
flex: 55%;
14+
}
15+
16+
.form-time-picker {
17+
flex: 45%;
18+
margin-left: 16px;
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-datetimepicker-template-driven-form',
5+
styleUrls: ['./template-driven-form.component.scss'],
6+
templateUrl: './template-driven-form.component.html'
7+
})
8+
export class DateTimePickerTDFSampleComponent {
9+
public date = new Date();
10+
}

src/app/scheduling/scheduling-routes-data.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export const schedulingRoutesData = {
2424
'datepicker-sample-8': { displayName: 'Custom Action Buttons', parentName: 'Datepicker' },
2525
'datepicker-sample-9': { displayName: 'Range Datepicker', parentName: 'Datepicker' },
2626
'datepicker-styling-sample': { displayName: 'Datepicker Styling', parentName: 'Datepicker' },
27+
'template-driven-form': { displayName: 'Date & Time Picker Template Driven Form', parentName: 'Datepicker' },
28+
'reactive-form': { displayName: 'Date & Time Picker Reactive Form', parentName: 'Reactive Forms' },
2729
'datetime-basic': { displayName: 'Date Time Basic', parentName: 'Date Time Editor' },
2830
'datetime-advanced': { displayName: 'Date Time Advanced', parentName: 'Date Time Editor' },
2931
'monthpicker-sample-1': { displayName: 'Default Month Picker', parentName: 'Monthpicker' },

src/app/scheduling/scheduling-routing.module.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { DatepickerSample6Component } from './datepicker/datepicker-sample-6/dat
2424
import { DatepickerSample7Component } from './datepicker/datepicker-sample-7/datepicker-sample-7.component';
2525
import { DatepickerSample8Component } from './datepicker/datepicker-sample-8/datepicker-sample-8.component';
2626
import { DatepickerStylingSampleComponent } from './datepicker/datepicker-styling-sample/datepicker-styling-sample.component';
27+
import { DateTimePickerTDFSampleComponent } from './datepicker/template-driven-form/template-driven-form.component';
28+
import { DateTimePickerRFSampleComponent } from './datepicker/reactive-form/reactive-form.component';
2729
import { BasicDateRangePickerComponent } from './daterangepicker/daterangepicker-basic/daterangepicker-basic';
2830
import {
2931
FlightBookingComponent } from './daterangepicker/daterangepicker-flight-booking/daterangepicker-flight-booking';
@@ -152,6 +154,16 @@ export const schedulingRoutes: Routes = [
152154
data: schedulingRoutesData['datepicker-sample-8'],
153155
path: 'datepicker-sample-8'
154156
},
157+
{
158+
component: DateTimePickerTDFSampleComponent,
159+
data: schedulingRoutesData['template-driven-form'],
160+
path: 'template-driven-form'
161+
},
162+
{
163+
component: DateTimePickerRFSampleComponent,
164+
data: schedulingRoutesData['reactive-form'],
165+
path: 'reactive-form'
166+
},
155167
{
156168
component: DateTimeBasicComponent,
157169
data: schedulingRoutesData['datetime-basic'],

src/app/scheduling/scheduling.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CommonModule } from '@angular/common';
22
import { NgModule } from '@angular/core';
3-
import { FormsModule } from '@angular/forms';
3+
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
44
import {
55
IgxAutocompleteModule, IgxButtonModule, IgxCalendarModule, IgxCardModule, IgxDatePickerModule,
66
IgxDateRangePickerModule, IgxDateTimeEditorModule, IgxDialogModule, IgxDropDownModule, IgxIconModule,
@@ -33,6 +33,8 @@ import { DatepickerSample8Component } from './datepicker/datepicker-sample-8/dat
3333
import { AutocompletePipeStartsWith, DatepickerSample9Component, PipeWithoutTownFrom
3434
} from './datepicker/datepicker-sample-9/datepicker-sample-9.component';
3535
import { DatepickerStylingSampleComponent } from './datepicker/datepicker-styling-sample/datepicker-styling-sample.component';
36+
import {DateTimePickerTDFSampleComponent} from './datepicker/template-driven-form/template-driven-form.component';
37+
import {DateTimePickerRFSampleComponent} from './datepicker/reactive-form/reactive-form.component';
3638
import {
3739
BasicDateRangePickerComponent } from './daterangepicker/daterangepicker-basic/daterangepicker-basic';
3840
import {
@@ -83,6 +85,8 @@ import { TimePickerStylingComponent } from './timepicker/timepicker-styling/time
8385
DatepickerSample7Component,
8486
DatepickerSample8Component,
8587
DatepickerSample9Component,
88+
DateTimePickerTDFSampleComponent,
89+
DateTimePickerRFSampleComponent,
8690
DateTimeBasicComponent,
8791
DatepickerDropdownComponent,
8892
DatepickerStylingSampleComponent,
@@ -107,6 +111,7 @@ import { TimePickerStylingComponent } from './timepicker/timepicker-styling/time
107111
imports: [
108112
CommonModule,
109113
FormsModule,
114+
ReactiveFormsModule,
110115
SchedulingRoutingModule,
111116
IgxAutocompleteModule,
112117
IgxCalendarModule,

0 commit comments

Comments
 (0)