1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
<html dir="ltr"><head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META HTTP-EQUIV="assetid" CONTENT="HV01021368"><META NAME="lcid" CONTENT="1033"><title>OnBeforeChange Event</title><link rel="stylesheet" type="text/css" href="office10.css"><script type="text/javascript" language="Javascript" src="ExpCollapse.js"></script><script type="text/javascript" language="JavaScript" src="inline.js"></script></head><body><p id="ExpandAllLine" class="ExpFav"><a href="#" onclick="ExpandAll()" onkeypress="ExpandAll()" class="DropDown"><img id="picHeader" border="0" src="expandtri.gif" alt="Show All"><span id="ExpandAll">Show All</span></a></p><h1>OnBeforeChange Event</h1><DIV class="ofvbanav"><span class="ofvbanavreuse" id="seealso" onclick="toggleList()" onkeypress="toggleList()"></span><span class="ofvbanavreuse" id="appliesto" onclick="toggleList()" onkeypress="toggleList()"></span><a class="ofvbanavex" href="#example"><span class="ofvbanavreuse" id="example"></span></a><span class="ofvbanavreuse" id="specifics" onclick="toggleList()" onkeypress="toggleList()"></span></DIV><p>
<p>Occurs after changes to a form's underlying XML document have been made but before the changes are accepted.</p>
<p class="signature">Function <i>node</i>::<b class="bterm">OnBeforeChange</b>(ByRef <b class="bterm"><i>pDataDOMEvent</i></b> As DataDOMEvent)</p>
<p>
<b class="bterm">
<i>pDataDOMEvent</i>
</b>Required <b class="bterm">DataDOMEvent</b>. A reference to the <b class="bterm"><a href="xdobjDataDOMEvent.htm" id="HV01021239" lcid=" ">DataDOMEvent</a></b> object.</p>
</p><h2>Remarks</h2><p>
<p>This <a href="#" class="glossary" onclick="AppendPopup(this,'xdeventhandler')" onkeypress="AppendPopup(this,'xdeventhandler')">event handler</a> allows users to cancel an operation.</p><p>During the <b class="bterm">OnBeforeChange</b> event, the form's underlying XML document is placed in read-only mode. If the <b class="bterm"><a href="xdproReturnStatus_1.htm" id="HV01021327" lcid=" ">ReturnStatus</a></b> property of the <b class="bterm">DataDOMEvent</b> object is set to False, Microsoft Office InfoPath 2003 rejects the changes that were made and a message box is displayed to the user. If an error occurs in the scripting code for the OnBeforeChange event handler, InfoPath rejects the changes and restores the data to its previous state.<p><b>Notes</b></p><ul><li>It is best to avoid switching views during the <b class="bterm">OnBeforeChange</b> event; changes have not yet been accepted, and switching to another view may result in an error.</li><li>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.</li><li>If a validation error is encountered in any <b class="bterm">OnBeforeChange</b> event handler, the document fails to load. A <code>try-catch</code> block in the <a href="xdevtOnLoad.htm" id="HV01021369" lcid=" "><b class="bterm">OnLoad</b></a> event can be used to catch this validation failure and to load the document despite the error.</li></ul></p>
</p><h2><a id="#example" name="#example">Example</a></h2><p>
<p>In the following example from the Events developer sample form, the OnBeforeChange event handler is used to validate the data in a field. If the data is not valid, the <b class="bterm">ReturnStatus</b> property of the <b class="bterm">DataDOMEvent</b> object is used to reject the changes.</p>
<pre><code>function msoxd__RepVisitDt::<b class="bterm">OnBeforeChange</b>(eventObj)
{
var oNode = XDocument.DOM.selectSingleNode
("/Customers/CustomerInfo/ContactDates/PhoneContactDt");
if (!oNode.text)
{
eventObj.ReturnMessage = "The Phone Contact Start date must be
set prior to the Representative Visit date.";
eventObj.ReturnStatus = false;
return;
}
// If the data is valid, eventObj.ReturnStatus = true.
eventObj.ReturnStatus = true;
return;
}</code></pre>
</p><script type="text/javascript" language="JScript" src="ofvbanl.js"></script><span id="ofVBAISpan" class="ofvbaispan"><iframe id="ofVBAIFrame" frameborder="0" marginheight="0" marginwidth="4" scrolling="auto" width="100%" src="../links/xdevtOnBeforeChange_l.htm"></iframe></span><center><a href="XMLSchemaCopyright_HV01147162.htm">©2003-2004 Microsoft Corporation. All rights reserved.</a>
Permission to copy, display and distribute this document is available at: <a
href="http://r.office.microsoft.com/r/rlidAWSContentRedir?AssetID=XT010988631033&CTT=11&Origin=HV011232471033"
target="_new">http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp</a></center></body></html>
|