Essentially, I am facing a challenge with validating form inputs that are interdependent (for example, ensuring that the "from" time is earlier than the "to" time). However, I'm unsure of the best approach to tackle this issue.
Below is my form group setup:
this.form = this.fb.group({
fromTime: ["", [Validators.required, CustomValidator.myValidationFunction(this.form.get("toTime").value)]],
toTime: ["", [Validators.required]]
});
Here is the current state of my custom validator:
static myValidationFunction(testing) {
const toTime = testing; // set only once
return control => {
return toTime /*this value remains constant*/ ? null : { test: {} };
};
}
It appears that the value x
or toTime
is initialized only during the creation of the validator. Is there a method to pass dynamic inputs to a custom validator?
While I have reviewed Angular's documentation on custom form validation, I have been unable to find a solution to my particular issue.