We've created elements, created a ruleset with some rules, and have captured a request from an html form. Our next step is to take a look at a few ways that we can perform validation on the elements, and also see how errors and validity are indicated within the component.
Many times when validating information from a form you simply want to determine whether all of the information is valid or not, this is easily accomplished with the Validate method of the ASPFormV1 class. In our example, we simply would call validate, if you have multiple rulesets configured ( something that won't be talking about in this example ), then you can either specify a ruleset or specify nothing and have all rulesets validate against the data. The example below shows how we would validate our example, note that validate returns whether the data is valid, this information is also stored in the IsValid property of the class.
There are times where you might want to validate a single element instead of your entire element set. To facilitate this two different methods were created, one allows you to specify the element name to validate from the ASPFormV1's validate method, the other is using a validate method that we created for the element class, this method has an optional argument to allow you to specify a ruleset name ( multiple rulesets are not being utilized in this example, so we will just leave it blank ). Below is an example of how we might validate the name element.
As seen above the IsValid property is available in both the ASPForm class and the Element class. IsValid returns false until it is validated, that way you don't have to worry about forgetting to validate your elements and the thing returning true, that would be bad.
The IsDirty flag is another property that should be mentioned at this time, the IsDirty flag simply indicates whether the value of an element has changed since the last the element was validated, it works like you would expect, simply returning a boolean value.