So far, we can define validation rules, and have state to track validation error messages, but nothing is invoking the rules yet. This is what we are going to implement in this section:
- We need to create a method within the Form component that is going to validate a field, calling the specified validator function. Let's create a method called validate that takes in the field name and its value. The method will return an array of validation error messages:
private validate = ( fieldName: string, value: any): string[] => { };
- Let's get the validation rules for the field and initialize an errors array. We'll collect all the errors in the errors array as the validators are executed. We'll also return the array of ...