I am using below code in component.html
<button class="btn btn-primary" [disabled]="!projectForm.valid"
(click)="updateProjects()">Update</button>
Component.ts code is below
this.projectForm = this.formBuilder.group({
Name: new FormControl('', [Validators.required, Validators.pattern('^[a-zA-Z1-9][a-zA-Z1-9, _-]+$')]),
ProjectID: new FormControl({ value: 'SQ123', disabled: true }),
ProjectTypeID: new FormControl({ value: null, disabled: true}),
ProjectSubTypeID: new FormControl({ value: null, disabled: true}),
LifecycleTemplate: new FormControl('Plan', [Validators.required]),
ConstructionTypeID: new FormControl({ value: null, disabled: true }, [Validators.required]),
ContractTypeID: new FormControl({ value: null, disabled: true }, [Validators.required]),
StartDate: new FormControl('', [Validators.required]),
StartDateSub: new FormControl('', [Validators.required]),
EndDate: new FormControl(''),
EndDateSub: new FormControl(''),
ProjectAddress: new FormControl({ value: null, disabled: true }, [Validators.required]),
Description: new FormControl(''),
});
this.projectForm.controls['StartDateSub'].valueChanges.subscribe(value => {
this.validateStartandEndDataSub();
});
this.projectForm.controls['EndDateSub'].valueChanges.subscribe(value => {
this.validateStartandEndDataSub();
});
while using the this.validateStartandEndDataSub(); function update button is not enabling due to this.validateStartandEndDataSub();
how to resolve the error to enable update button after filling all the values
validateStartandEndDataSub() {
const startDate = this.projectFormControls['StartDateSub'].value;
const endDate = this.projectFormControls['EndDateSub'].value;
if (endDate) {
if (startDate > endDate) {
this.projectFormControls['EndDateSub'].setErrors({ 'incorrect': true });
} else {
this.projectFormControls['EndDateSub'].setErrors({'incorrect': false});
}
}
}
validateStartandEndDataSubfunction?