pp108 : xforms-onvalidate

xforms-onvalidate

This event is fired after the value of the control is successfully validated against the available XSD information.

It is a custom-script validation, using which you can perform your own validation. This enables you to perform additional business validations on the entered value of the business object(s), which could not be defined in the XSD.

Syntax

DesignTime

This is a design-time property and can be set through the property sheet of the control.

Event Information

To invoke

Make a change to the value of the controls and shift the focus to other controls.

Default Action

Initiates any action associated with this event.

Named Script

xforms_onvalidate

Event Object Properties

Property

Description

errorMessage

Contains an error message that is displayed in case of custom validation error. If not specified, no error message is displayed and the field is highlighted to indicate the error.

oFeedbackObject

Optional. A JavaScript object that enables the notification description as a hyperlink. Clicking the description opens the detailed message separately. This object comprises the following properties:

  • applicationDefinition : If specified, application.select() will be executed with the application definition, on click of the notification message.
  • callbackFunction : It denotes a function pointer. When specified, it will be executed on click of the notification message.
  • relatedHTMLelement : It denotes an HTML object. When specified, it will set the focus to the HTML object on click of the notification message.
  • detail : It refers to an XML element node. When specified, it displays the details of the notification message in a separate window that can be expanded or collapsed using the More or Less option.

srcElement

Reference to the control whose value is validated

valid

Boolean that denotes whether the entered value is valid or not. If the value is not valid, you can set this attribute to false.

  • true: Default. Entered value is valid.
  • false: Entered value is not valid. The corresponding field is outlined in red color to highlight it, and a notification message displays.

An event handler can access the event object and its properties through the eventObject available as a parameter on the handler.

Remarks

The onvalidate event is used to do any business validations that are not part or possible through standard XSD. This event will not be fired if the value entered is not valid as per the validation defined in standard XSD.

Example

The following sample codes demonstrate the use of this event to apply custom validations:

function onValidate(eventObject)
{
	var value = eventObject.srcElement.value;
	//A custom validation
	if (value.indexOf("custom") >= 0)
	{
		//Cancel synchronizing the data
		eventObject.valid = false;
		alert("Data contains custom content that cannot be accepted.");
	}
}
var value = eventObject.srcElement.value;
//if value is < 1, then its invalid
if (value < 1)
{
	eventObject.valid = false;
	eventObject.errorMessage = "This value is invalid. Enter value >= 1";
}
else
{
	eventObject.valid = true;
}

Applies to

Input, Output, Password, Textarea, Check, Radio, Select, List