new shizzle for nizzle
This commit is contained in:
18
src/app/models/validators/time-after-start-validator.ts
Normal file
18
src/app/models/validators/time-after-start-validator.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import {AbstractControl, ValidationErrors, ValidatorFn} from '@angular/forms';
|
||||
|
||||
export function timeAfterStartValidator(startTimeField: string): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationErrors | null => {
|
||||
const startTime = control.parent?.get(startTimeField)?.value;
|
||||
const endTime = control.value;
|
||||
|
||||
if (!startTime || !endTime) {
|
||||
return null; // Niet valideren als een van beide leeg is
|
||||
}
|
||||
|
||||
// Omzetten naar Date-objecten voor vergelijking
|
||||
const start = new Date(`1970-01-01T${startTime}:00`);
|
||||
const end = new Date(`1970-01-01T${endTime}:00`);
|
||||
|
||||
return end > start ? null : {endTimeInvalid: true};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user