Closed ludetc closed 4 months ago
we can also add a date picker filter, so that pasted dates are disabled from selection:
https://material.angular.io/components/datepicker/examples
Datepicker with filter validation
export function futureDateValidator(): ValidatorFn { return (control: AbstractControl): { [key: string]: any } | null => { const date = new Date(control.value); const today = new Date(); // Reset the time to compare only dates today.setHours(0, 0, 0, 0); return date > today ? null : { notFutureDate: { value: control.value } }; }; }
A benefit of using validator is that it propagate up all the way to the form level validation, so the submit/save button can be disabled on all those validators. This approach does not need to introduce any new variables in the ts file.
I think I like your datepicker option best
I think I like your datepicker option best
I'm not saying pick one, I think we should do both. They function differently. one is for form validator, another is for better user experience. User can manipulate the input any way they want, the date picker will not prevent they change the input value.