1
- import { Component , Input , ViewChild , computed , forwardRef , input , output } from '@angular/core' ;
1
+ import { Component , Input , ViewChild , computed , forwardRef , input , output , signal } from '@angular/core' ;
2
2
import { ControlValueAccessor , NG_VALUE_ACCESSOR , NgModel } from '@angular/forms' ;
3
3
import { faCalendarAlt , faCircleXmark , faClock , faGlobe , faQuestionCircle , faTriangleExclamation } from '@fortawesome/free-solid-svg-icons' ;
4
4
import dayjs from 'dayjs/esm' ;
@@ -37,13 +37,27 @@ export class FormDateTimePickerComponent implements ControlValueAccessor {
37
37
shouldDisplayTimeZoneWarning = input < boolean > ( true ) ; // Displays a warning that the current time zone might differ from the participants'.
38
38
valueChange = output < void > ( ) ;
39
39
40
+ protected isInputValid = signal < boolean > ( false ) ;
41
+ protected dateInputValue = signal < string > ( '' ) ;
42
+
43
+ isValid = computed ( ( ) => {
44
+ const isInvalid = this . error ( ) || ! this . isInputValid ( ) || ( this . requiredField ( ) && ! this . dateInputValue ( ) ) || this . warning ( ) ;
45
+ return ! isInvalid ;
46
+ } ) ;
47
+
48
+ private updateSignals ( ) : void {
49
+ this . isInputValid . set ( ! Boolean ( this . dateInput . invalid ) ) ;
50
+ this . dateInputValue . set ( this . dateInput . value ) ;
51
+ }
52
+
40
53
private onChange ?: ( val ?: dayjs . Dayjs ) => void ;
41
54
42
55
/**
43
56
* Emits the value change from component.
44
57
*/
45
58
valueChanged ( ) {
46
59
this . valueChange . emit ( ) ;
60
+ this . updateSignals ( ) ;
47
61
}
48
62
49
63
/**
@@ -57,6 +71,7 @@ export class FormDateTimePickerComponent implements ControlValueAccessor {
57
71
} else {
58
72
this . value = value ;
59
73
}
74
+ this . updateSignals ( ) ;
60
75
}
61
76
62
77
/**
@@ -117,5 +132,6 @@ export class FormDateTimePickerComponent implements ControlValueAccessor {
117
132
*/
118
133
clearDate ( ) {
119
134
this . dateInput . reset ( undefined ) ;
135
+ this . updateSignals ( ) ;
120
136
}
121
137
}
0 commit comments