Share via


DataDOM.OnValidate Event

InfoPath Developer Reference

Occurs after changes to a form's underlying XML document have been accepted but before the OnAfterChange event occurs.

Version Information
 Version Added:  InfoPath 2003

Syntax

expression.OnValidate(pDataDOMEvent)

expression   An expression that returns a DataDOM object.

Parameters

Name Required/Optional Data Type Description
pDataDOMEvent Required DataDOMEvent An event object that is used during Microsoft Office InfoPath 2007 data validation events.

Return Value
nothing

Remarks

This event handler does not allow users to cancel an operation.

During the OnValidate event, the form's underlying XML document is placed in read-only mode.

The OnValidate event is typically used for handling errors and working with the Errors collection—for example, adding new errors or deleting existing ones.

Bb229743.vs_note(en-us,office.12).gif  Note
In some cases, events related to changes in a form's underlying XML document may occur more than once. For example, when existing data is changed, an insert and delete operation occurs.

Example

In the following partial example, the OnValidate event handler is used to validate contact information. If the data is invalid, the ReportError method of the DataDOMEVent object is used to create an error.

JScript
  function msoxd__ContactDates::OnValidate eventObj)
{
   var iNumberOfDays = 0;
   var objEmailDate = XDocument.DOM.selectSingleNode
      ('/Customers/CustomerInfo/ContactDates/EmailCampaignDt');
   var objPhoneContactDate = XDocument.DOM.selectSingleNode
      ('/Customers/CustomerInfo/ContactDates/PhoneContactDt');
   var objRepVisitDate = XDocument.DOM.selectSingleNode
      ('/Customers/CustomerInfo/ContactDates/RepVisitDt');

// First validate the email and phone contact dates. if (!objEmailDate || !objPhoneContactDate) return;

var emailDate = new Date(objEmailDate.text.replace(/(.)-(.)-(.)/, "$2-$3-$1")); var phoneContactDate = new Date(objPhoneContactDate.text.replace(/(.)-(.)-(.)/, "$2-$3-$1"));

if (isNaN(emailDate) || isNaN(phoneContactDate)) return;

// Get the number of days between the two dates. iNumberOfDays = GetElapsedDays(emailDate, phoneContactDate);

if (iNumberOfDays < REQUIRED_PHONE_EMAIL_INTERVAL) eventObj.ReportError(objPhoneContactDate, "The Phone Contact Start date must occur after " + REQUIRED_PHONE_EMAIL_INTERVAL + " days from the start of the Email Campaign.", false); ... }

See Also