The MForm controls use the ASP.NET validation scheme.
There is a separate validator control for the Root control, it is called
the RootValidator. This validator inherits from the ASP.NET BaseValidator
class.
All the properties available to standard .NET validators are also available in the
RootValidator. These are:
ControlToValidate - the ID of the Root control, that the validator
is attached to.
ValidationGroup - a named group of common validators
Text - a static text displayed on error
Display - a display type: None, Static or Dynamic
If the error should be displayed somewhere else, the .NET ValidationSummary
control may be used.
The RootValidator control coordinates the validation of the controls
tree inside the Root control, both on the client and on the server
side.
Each of the MForm item controls may contain a Constraint object inside
the Additions property. The Constraint property must implement
the IsValid method, that takes the item as the parameter - this way
the validation is perforemed on server side. Each class inheriting form the Constraint
also adds a client script resource to the page. When the MForm item is loaded on
the client side, it has all the constraints registered - and they are checked on
item values change - this way the validation is performed on the client side.
For existing MForm item constraints look in the Constraints chapter.
In order to reduce verbosity of the MForm controls tree, one constraint does not need to be added to every leaf definition.
This constraint is called the DataTypeConstraint and it checks if the data inside the leaf item matches the data type of the item.
The data type constraint, like some of the built-in constraint, has some predefined error messages defined. These error messages are in the MForm resource files.
To change the default error message, the data type constraint needs to be added explicitly to the item additions, and needs to have the ErrorText property set.
Every constraint has an ErrorText property. This property is a description
of the error in case of a situation when the constraint is not met.
When MForm is validated, it stops for the first constraint that is not matched.
The displayed error text concerns the item that is the owner of the constraint.
By default, the error message will only be shown on button pressing and will display
only the data about the errorneous field.
For a solution to add error messages near the fields, check the
Error label example page