NG ValidatorPack introduces a set of components which allow implementation of professional-level client-side validation in an elegant and clear way without writing much code (often without any code at all).
The two main tasks of client-side validation are:
•to check for validity a value entered by a user into some input control;
•to provide feedback about validation results (e.g. to indicate an error) in some way.
Consequently, there are three types of components involved into the most typical validation setup :
•input control being validated;
•validator component which encapsulates some validation logic;
•error provider component which implements some way of error indication.
NG ValidatorPack includes a number of example controls with validation support. These controls implements INGValidatedControl interface. Most widely used standard VCL controls are included. Any third-party or custom controls can be enabled to support validation by NG ValidatorsPack by implementing INGValidatedControl interface (see How to Create a New Validated Control topic for details).
Each of validated controls has the Validator property pointing to a validator component which defines how values entered into this control should be validated. The ValidationMsg property gives control over the feedback message which is typically used by error provider component for error indication (see Validated Input Controls topic for details).
The validation components can be divided in two groups:
•Validators, that represent pieces of validation logic (validation rules); they can be grouped by the Validation Group component - a special type of validator, which allows for using several validators together to implement more complex validation rules in a declarative way (see Validation Group topic for details);
•Error Providers, that represent a ways of error indication (feedback to user); they can be grouped by the Error Providers Group component - a special type of error provider which allows for using several ways of error indication (e.g. icons and hint messages) together (see Error Provider Groups topic for details).
Error providers are connected to validators using their Provider property. Validation Group component directly support multiple error providers with its Providers collection property; other validators can employ multiple error providers using the Error Providers Group component assigned to their Provider property.
So, the typical validation setup is the following: the validated input control MyControl has a MyValidator validator component assigned to its Provider property; there's a MyProvider error provider assigned to the Provider property of MyValidator. Each time the value in the MyControl changes, the Validate function of MyValidator is called; if it returns a non-zero ErrorLevel value, it means that the value violates the validation rule (e.g. doesn't match a specified regular expression) and the DisplayError function of the MyProvider is called which performs some sort of error indication, e.g. displays a hint message which is generally assembled using the ErrorMessage property of MyValidator and the ValidationMsg property of MyControl. As DisplayError function gets MyControl reference as a parameter, the error indication can be performed in a control-specific way e.g. an icon is displayed near this control, or the hint is set for this control.