@@ -21,46 +21,46 @@ import {FormControl} from '@angular/forms';
21
21
</mat-datepicker-toggle>
22
22
<mat-form-field class="example-full-width">
23
23
<input
24
- *ngIf="enableTime && enableDate"
25
- matInput
26
- type="datetime-local"
27
- [placeholder]="instance.component.placeholder"
28
- [formControl]="displayControl"
29
- (input)="onChange ()"
30
- readonly
24
+ *ngIf="enableTime && enableDate"
25
+ matInput
26
+ type="datetime-local"
27
+ [placeholder]="instance.component.placeholder"
28
+ [formControl]="displayControl"
29
+ (input)="onChangeInput ()"
30
+ [ readonly]="!allowManualInput"
31
31
>
32
32
<input
33
- *ngIf="enableTime && !enableDate"
34
- matInput
35
- [placeholder]="instance.component.placeholder"
36
- [formControl]="displayControl"
37
- [matMask]="formatTime"
38
- (input)="onChange ()"
39
- readonly
33
+ *ngIf="enableTime && !enableDate"
34
+ matInput
35
+ [placeholder]="instance.component.placeholder"
36
+ [formControl]="displayControl"
37
+ [matMask]="formatTime"
38
+ (input)="onChangeInput ()"
39
+ [ readonly]="!allowManualInput"
40
40
>
41
41
<input
42
- *ngIf="!enableTime && enableDate"
43
- matInput
44
- [placeholder]="instance.component.placeholder"
45
- [formControl]="displayControl"
46
- (input)="onChange ()"
47
- readonly
42
+ *ngIf="!enableTime && enableDate"
43
+ matInput
44
+ [placeholder]="instance.component.placeholder"
45
+ [formControl]="displayControl"
46
+ (input)="onChangeInput ()"
47
+ [ readonly]="!allowManualInput"
48
48
>
49
49
</mat-form-field>
50
50
51
51
<mat-formio-calendar
52
- #calendar
53
- [minDate]="instance.component.datePicker.minDate || ''"
54
- [maxDate]="instance.component.datePicker.maxDate || ''"
55
- [dateFilter]="dateFilter"
56
- [hidden]="!isPickerOpened"
57
- (dateSelectEvent)="onChangeDate($event)"
58
- (timeSelectEvent)="onChangeTime($event)"
59
- [enableDate]="enableDate"
60
- [enableTime]="enableTime"
61
- [hourStep]="instance.component.timePicker.hourStep"
62
- [minuteStep]="instance.component.timePicker.minuteStep"
63
- [instance]="instance"
52
+ #calendar
53
+ [minDate]="instance.component.datePicker.minDate || ''"
54
+ [maxDate]="instance.component.datePicker.maxDate || ''"
55
+ [dateFilter]="dateFilter"
56
+ [hidden]="!isPickerOpened"
57
+ (dateSelectEvent)="onChangeDate($event)"
58
+ (timeSelectEvent)="onChangeTime($event)"
59
+ [enableDate]="enableDate"
60
+ [enableTime]="enableTime"
61
+ [hourStep]="instance.component.timePicker.hourStep"
62
+ [minuteStep]="instance.component.timePicker.minuteStep"
63
+ [instance]="instance"
64
64
></mat-formio-calendar>
65
65
<mat-error *ngIf="instance.error">{{ instance.error.message }}</mat-error>
66
66
</form>
@@ -74,6 +74,7 @@ export class MaterialDateComponent extends MaterialComponent {
74
74
public isPickerOpened : boolean ;
75
75
public selectedDate : any ;
76
76
public selectedTime : any = '00:00' ;
77
+ public allowManualInput : boolean = true ;
77
78
78
79
@ViewChild ( 'calendar' , { static : false } ) calendar ;
79
80
@@ -110,6 +111,14 @@ export class MaterialDateComponent extends MaterialComponent {
110
111
}
111
112
}
112
113
114
+ onChangeInput ( ) {
115
+ const value = this . dateFilter ( this . displayControl . value ) &&
116
+ this . checkMinMax ( this . displayControl . value ) ? this . displayControl . value : '' ;
117
+
118
+ this . control . setValue ( value ) ;
119
+ this . onChange ( ) ;
120
+ }
121
+
113
122
getDateTimeValue ( ) {
114
123
let newDate = '' ;
115
124
let isSelectedTime = false ;
@@ -160,15 +169,16 @@ export class MaterialDateComponent extends MaterialComponent {
160
169
this . isDisabled ( ) ? this . displayControl . disable ( ) : this . displayControl . enable ( ) ;
161
170
162
171
if ( this . instance ) {
172
+ this . allowManualInput = this . instance . component . allowInput === false ? false : true ;
163
173
if ( this . instance . component && this . instance . component . datePicker ) {
164
- const { minDate : min , maxDate : max } = this . instance . component . datePicker ;
174
+ const { minDate : min , maxDate : max } = this . instance . component . datePicker ;
165
175
166
- // It improves the date to the full format if the customer set only a year. Otherwise we will have conflicts into the moment.js.
167
- const { minDate, maxDate } = this . improveMinMaxDate ( min , max ) ;
168
- this . instance . component . datePicker . minDate = minDate ;
169
- this . instance . component . datePicker . maxDate = maxDate ;
176
+ // It improves the date to the full format if the customer set only a year. Otherwise we will have conflicts into the moment.js.
177
+ const { minDate, maxDate } = this . improveMinMaxDate ( min , max ) ;
178
+ this . instance . component . datePicker . minDate = minDate ;
179
+ this . instance . component . datePicker . maxDate = maxDate ;
170
180
}
171
- }
181
+ }
172
182
}
173
183
174
184
toggleCalendar ( event ) {
0 commit comments