The validate event handler

The validate function handles validation errors that are caused by the data in the view.

Usage

The validate function contains the logic to display indicators or some other notifier that there is a problem with the data. The framework starts with the validate function in parent views before it calls the validate function in their children views.

The validate event handler is for when you want to provide custom error visualizations and behavior. See the stock controls for examples of presentation logic. For example, the Text stock control changes color and displays an error icon when it contains non-valid data. The error icon has hover help that displays the message that is associated with the error condition.

The event object

The validate function takes a single event object. The type of the event object is error or clear. An error event means that a validation service or script has detected one or more errors and that the view must handle the errors to display an appropriate visualization. A clear event means that the view must remove the visualization that resulted from an earliererror event.

An error event can have two lists of error objects. One list is named errors and the other is named errors_subscription. Views that are bound to a business object automatically receive errors for themselves. They also automatically receive errors for all descendant views that are bound to the same business object.

Table 1. Properties of the error objects in the errors list
Property Type Description
binding String Contains the path to the data binding relative to the data binding of the current view.
message String Contains the localized message that describes the error.
view_dom_ids[] String[List] Contains the list of DOM IDs of the views that receive the same error message. The list can include the current view and any of its descendant views.
Views that call subscribeValidation() receive certain errors in the errors_subscription list. These errors occur in descendant views that are bound to a different business object than the current view. Views that do not have a data binding, such as the Tab stock control, must call subscribeValidation() to receive errors.
Table 2. Properties of the error objects in the errors_subscription list
Property Type Description
messages String[List] Contains a list of localized error messages
view_dom_id String Contains the DOM ID of the view with the non-valid data.
An error event object might look like this example:
type: "error",
errors: 
	[
		{
			binding: "birthday.year"
			message: "The year you entered, 2013, is after current year of 2012.",
			view_dom_ids: ["domId_ProfileView", "domId_yearView"]
		}
	]
errors_subcription: 
	[
		{
			view_dom_id: "domId_accountView",
			messages: ["Enter your account number."]
		}
	]

A clear event object contains no properties. A view uses the clear object to remove the error indicators for views that now have valid data.