Ecodev / natural

Angular Material components and various utilities
https://ecodev.github.io/natural
MIT License
1 stars 2 forks source link

Date validator #92

Open PowerKiKi opened 3 years ago

PowerKiKi commented 3 years ago

A date validator to which we give a DateAdapter and that validate that whatever we give is either a valid string representation of a date, or a Date. So basically forwarding to DateAdapter.isValid.

It should be used used pretty much for every datepicker in all our projects.

Usage is something like:

constructor(
    dateAdapter: DateAdapter,
) {
    const formControl = new FormControl(null, [date(dateAdapter)]);
}
PowerKiKi commented 3 years ago

Pseudo-code

function date(dateAadapter) : ValidatorFn {
    return (fromControl)=> { dateAdapter.isValid(formControl.value); }
}