Hey,
The issue seems to be with the following code:
<ejs-datepicker [openOnFocus]='false' [showTodayButton]='false' [min]="dateMin" [max]="dateMax" [enableMask]="true" [formControl]="newProviderForm.get('DateOfBirth')" format="MM/dd/yyyy" [maskPlaceholder]="maskPlaceholderValue"> </ejs-datepicker> |
Steps to replicate issue:
Berly,
"We would like to inform you that, the reported issue is not related to form validation and this is component’s built-in range validation."
That is... the issue.
Why does the control carry a validation system of its own? What is the point of having a red outline when it doesn't actually validate the control in any way? What is the use case of a validation system that doesn't validate the control? This is most definitely not the expected behaviour, as it is inconsistent with literally any other prebuilt component found anywhere.
If the min-max field values apparently don't actually extend to the form validation, how are we supposed to validate the control?
"Similar that, if you are entering any valid date value which is beyond to the default min and max value means, the error class has been added and component state is maintained as valid."
I am aware of that- and that behaviour is even more problematic.
This means that getting value always returns null when it's not a valid date, making it impossible to apply any sort of manual validation.
Your attempt to justify the improper behaviour of the control leads me to believe that you are not acknowledging this as an issue.
It seems like the solution here is to move away from using Syncfusion controls in it's entirety as they are fundamentally nowhere near feature complete.
Please escalate this issue as it makes the control completely useless.
function minDateValidator(min: Date, value: Date) {
return (control): { [key: string]: boolean } | null => {
if (+min < +control.value) {
return { minDateValidator: false };
} else {
return { minDateValidator: true };
}
};
}
function maxDateValidator(max: Date, value: Date) {
return (control): { [key: string]: boolean } | null => {
if (+max > +control.value) {
return { maxDateValidator: false };
} else {
return { maxDateValidator: true };
}
};
}
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
encapsulation: ViewEncapsulation.None,
providers: [MaskedDateTimeService]
})
export class AppComponent {
@ViewChild('dateObj')
public datepickerObject: DatePickerComponent;
min = new Date('8/1/2021');
max = new Date('8/31/2021');
value = new Date('08/19/2022');
dateMask = 'MM/dd/yyyy';
maskPlaceholderValue = 'MM/dd/yyyy';
skillForm: FormGroup;
createForm(): void {
this.skillForm = this.fb.group({
date: [
this.value,
[
minDateValidator(this.min, this.value),
maxDateValidator(this.max, this.value)
]
]
});
}
ngAfterViewInit() {
this.skillForm.controls['date'].updateValueAndValidity();
}
onClick() {
if (this.skillForm.valid) {
console.log('form submitted');
} else {
this.skillForm.controls['date'].updateValueAndValidity();
}
}
} |
<form [formGroup]="skillForm">
<ejs-datepicker [openOnFocus]='false' #dateObj [showTodayButton]='false' [enableMask]="true" format="MM/dd/yyyy"
[maskPlaceholder]="maskPlaceholderValue" formControlName="date" [(value)]="value" placeholder="Date"
floatLabelType="Auto" [min]="min" [max]="max">
</ejs-datepicker>
<span class='e-error' *ngIf= "skillForm.get('date').errors?.minDateValidator">Please select a date after min value</span>
<span class='e-error' *ngIf= "skillForm.get('date').errors?.maxDateValidator">Please select a date after max value</span>
<br/>
<button (click)="onClick($event)">Submit</button>
</form> |