@@ -6,11 +6,9 @@ import { DatePicker } from 'primeng/datepicker';
66import { InputText } from 'primeng/inputtext' ;
77import { Message } from 'primeng/message' ;
88
9- import { filter } from 'rxjs' ;
10-
119import { ChangeDetectionStrategy , Component , DestroyRef , inject , input , OnInit , output } from '@angular/core' ;
1210import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
13- import { FormControl , FormGroup , ReactiveFormsModule } from '@angular/forms' ;
11+ import { FormControl , FormGroup , ReactiveFormsModule , Validators } from '@angular/forms' ;
1412
1513import { TextInputComponent } from '@osf/shared/components' ;
1614import { InputLimits } from '@osf/shared/constants' ;
@@ -28,7 +26,7 @@ export class EducationFormComponent implements OnInit {
2826 readonly maxDate = MAX_DATE ;
2927 readonly minDate = MIN_DATE ;
3028 readonly institutionMaxLength = InputLimits . fullName . maxLength ;
31- readonly dateFormat = 'mm/dd/ yy' ;
29+ readonly dateFormat = 'mm/yy' ;
3230
3331 private readonly destroyRef = inject ( DestroyRef ) ;
3432
@@ -46,12 +44,30 @@ export class EducationFormComponent implements OnInit {
4644 return form . errors && form . errors [ 'dateRangeInvalid' ] ;
4745 }
4846
47+ get startDateRequiredError ( ) {
48+ const control = this . group ( ) . controls [ 'startDate' ] ;
49+ return control . invalid && control . errors ?. [ 'required' ] && ( control . touched || control . dirty ) ;
50+ }
51+
52+ get endDateRequiredError ( ) {
53+ const control = this . group ( ) . controls [ 'endDate' ] ;
54+ return control . invalid && control . errors ?. [ 'required' ] && ( control . touched || control . dirty ) ;
55+ }
56+
4957 ngOnInit ( ) {
5058 this . group ( )
51- . controls [ 'ongoing' ] . valueChanges . pipe (
52- filter ( ( res ) => ! ! res ) ,
53- takeUntilDestroyed ( this . destroyRef )
54- )
55- . subscribe ( ( ) => this . group ( ) . controls [ 'endDate' ] . setValue ( null ) ) ;
59+ . controls [ 'ongoing' ] . valueChanges . pipe ( takeUntilDestroyed ( this . destroyRef ) )
60+ . subscribe ( ( ongoing ) => {
61+ const endDateControl = this . group ( ) . controls [ 'endDate' ] ;
62+
63+ if ( ongoing ) {
64+ endDateControl . setValue ( null ) ;
65+ endDateControl . clearValidators ( ) ;
66+ } else {
67+ endDateControl . setValidators ( [ Validators . required ] ) ;
68+ }
69+
70+ endDateControl . updateValueAndValidity ( ) ;
71+ } ) ;
5672 }
5773}
0 commit comments