1
- import { ECalendarValue } from '../common/types/calendar-value-enum' ;
2
1
import { CalendarType } from './../common/types/calendar-type' ;
3
2
import { IDatePickerDirectiveConfig } from './date-picker-directive-config.model' ;
4
3
import { DatePickerDirectiveService } from './date-picker-directive.service' ;
@@ -15,6 +14,7 @@ import {
15
14
Optional
16
15
} from '@angular/core' ;
17
16
import { NgControl } from '@angular/forms' ;
17
+ import { Moment } from 'moment' ;
18
18
19
19
@Directive ( {
20
20
exportAs : 'dpDayPicker' ,
@@ -25,7 +25,9 @@ export class DatePickerDirective implements OnInit {
25
25
private _config : IDatePickerDirectiveConfig ;
26
26
private _attachTo : ElementRef | string ;
27
27
private _theme : string ;
28
- private _type : CalendarType ;
28
+ private _type : CalendarType = 'day' ;
29
+ private _minDate : Moment | string ;
30
+ private _maxDate : Moment | string ;
29
31
30
32
get config ( ) : IDatePickerDirectiveConfig {
31
33
return this . _config ;
@@ -68,6 +70,30 @@ export class DatePickerDirective implements OnInit {
68
70
}
69
71
}
70
72
73
+ @Input ( ) set minDate ( minDate : Moment | string ) {
74
+ this . _minDate = minDate ;
75
+ if ( this . datePicker ) {
76
+ this . datePicker . minDate = minDate ;
77
+ this . datePicker . ngOnInit ( ) ;
78
+ }
79
+ }
80
+
81
+ get minDate ( ) : Moment | string {
82
+ return this . _minDate ;
83
+ }
84
+
85
+ @Input ( ) set maxDate ( maxDate : Moment | string ) {
86
+ this . _maxDate = maxDate ;
87
+ if ( this . datePicker ) {
88
+ this . datePicker . maxDate = maxDate ;
89
+ this . datePicker . ngOnInit ( ) ;
90
+ }
91
+ }
92
+
93
+ get maxDate ( ) : Moment | string {
94
+ return this . _maxDate ;
95
+ }
96
+
71
97
public datePicker : DatePickerComponent ;
72
98
public api : IDpDayPickerApi ;
73
99
@@ -94,14 +120,20 @@ export class DatePickerDirective implements OnInit {
94
120
if ( ! this . formControl ) {
95
121
return ;
96
122
}
123
+
97
124
this . datePicker . onViewDateChange ( this . formControl . value ) ;
98
125
this . formControl . valueChanges . subscribe ( value => {
99
126
if ( value !== this . datePicker . inputElementValue ) {
100
127
this . datePicker . onViewDateChange ( value ) ;
101
128
}
102
129
} ) ;
103
- this . datePicker . registerOnChange ( value => {
130
+
131
+ this . datePicker . registerOnChange ( ( value ) => {
104
132
this . formControl . control . setValue ( this . datePicker . inputElementValue ) ;
133
+ const errors = this . datePicker . validateFn ( value ) ;
134
+ if ( errors ) {
135
+ this . formControl . control . setErrors ( errors ) ;
136
+ }
105
137
this . formControl . control . markAsDirty ( ) ;
106
138
} ) ;
107
139
}
@@ -120,6 +152,8 @@ export class DatePickerDirective implements OnInit {
120
152
121
153
private updateDatepickerConfig ( ) {
122
154
if ( this . datePicker ) {
155
+ this . datePicker . minDate = this . minDate ;
156
+ this . datePicker . maxDate = this . maxDate ;
123
157
this . datePicker . type = this . type || 'day' ;
124
158
this . datePicker . config = this . config ;
125
159
this . datePicker . init ( ) ;
0 commit comments