File: inconDVEventsInEVTForm.htm

package info (click to toggle)
office2003-schemas 1.0%2Bds-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 42,304 kB
  • sloc: javascript: 2,429; makefile: 29
file content (102 lines) | stat: -rw-r--r-- 13,026 bytes parent folder | download
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<html dir="ltr"><head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META HTTP-EQUIV="assetid" CONTENT="HV01027389"><META NAME="lcid" CONTENT="1033"><title>Data validation events in the Events developer sample form</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>Data validation events in the Events developer sample form</h1><div class="ofvbanav"><span class="ofvbanavreuse" id="seealso" onclick="toggleList()" onkeypress="toggleList()"></span><span class="ofvbanavreuse" id="specifics" onclick="toggleList()" onkeypress="toggleList()"></span></div><p>The Events developer sample form implements a variety of Microsoft Office InfoPath 2003
			<a href="#" class="glossary" onclick="AppendPopup(this,'xddatavalidation')" onkeypress="AppendPopup(this,'xddatavalidation')"> data validation</a> events that can be used to validate data that is entered into a form. Data validation events can occur after a change has been made to a <a href="#" class="glossary" onclick="AppendPopup(this,'xdfield')" onkeypress="AppendPopup(this,'xdfield')">field</a> or <a href="#" class="glossary" onclick="AppendPopup(this,'xdgroup')" onkeypress="AppendPopup(this,'xdgroup')">group</a>, after a change has been made to a field or group but before the data is committed, and after a change has been made to a field or group and after the data is committed.</p><p>To use one of the data validation events, you must first create the event in the <b class="ui">Field or Group Properties</b> dialog box that is available from the <b class="ui">Data Source</b>
			task pane. To access this dialog box, right-click one of the fields or groups in the task pane, and then click
			<b class="ui">Properties</b>. On the <b class="ui">Validation and Script</b> tab, select the event you wish to create, and then click <b class="ui">Edit</b>; this opens
			<a href="#" class="glossary" onclick="AppendPopup(this,'xdmicrosoftscripteditormse')" onkeypress="AppendPopup(this,'xdmicrosoftscripteditormse')">Microsoft Script Editor (MSE)</a> and displays the InfoPath-generated <a href="#" class="glossary" onclick="AppendPopup(this,'xdeventhandler')" onkeypress="AppendPopup(this,'xdeventhandler')">event handler</a>.</p><p><b>Note</b>  Event handlers in InfoPath must be created in <a href="#" class="glossary" onclick="AppendPopup(this,'xddesignmode')" onkeypress="AppendPopup(this,'xddesignmode')">design mode</a>.</p><p>The following table lists each of the data validation events implemented in the Events developer sample form, along with a description of how they are used.</p><table><tr><th>Event</th><th>Description</th></tr><tr><td><b class="bterm"><a href="xdevtOnValidate.htm" id="HV01021372" lcid=" ">OnValidate</a></b>
				</td><td>Used to validate the data contained in the ContactDates group. When this event occurs, scripting code  is used to verify that the dates used are within a specified range. </td></tr><tr><td><b class="bterm"><a href="xdevtOnBeforeChange.htm" id="HV01021368" lcid=" ">OnBeforeChange</a></b>
				</td><td>Used to validate the data contained in the Email Campaign Start, Phone Contact Start, and Representative Visit date fields. When this event occurs, scripting code is used to implement business logic that checks for the existence of certain dates before others can be entered or removed.</td></tr><tr><td><b class="bterm"><a href="xdevtOnAfterChange.htm" id="HV01021366" lcid=" ">OnAfterChange</a></b>
				</td><td>Used to call a function that calculates the total campaign costs and updates the Campaign Cost field.</td></tr></table><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Using the OnValidate event</a></p><div id="ExpCol" class="collapsed" border="0"><p>The <b class="bterm">OnValidate</b> event occurs after a change has been made to a field. When a user makes a change to a field and then leaves
					the field, the <b class="bterm">OnValidate</b> event can validate the data that the user entered.</p><p>In the Events developer sample form, the <b class="bterm">OnValidate</b> event validates the data entered in the ContactDates group, which includes the Email Campaign Start, Phone Contact Start, and Representative Visit date fields. When a user enters a date in any of these fields, either by typing it or by using the Date Picker control, the <b class="bterm">OnValidate</b> event occurs and the scripting code that it contains verifies that the dates entered do not exceed a specified interval. If they do exceed the specified interval, the <b class="bterm"><a href="xdmthReportError.htm" id="HV01021405" lcid=" ">ReportError</a></b> method of the <b class="bterm"><a href="xdobjDataDOMEvent.htm" id="HV01021239" lcid=" ">DataDOMEvent</a></b> object,
					which is the eventObj argument passed to the event handler, is used to notify the user. The following example from the Event developer sample form shows the 
					<b class="bterm">OnValidate</b> event handler:</p><pre><code>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(Application.FormatString
      (objEmailDate, "date", "dateFormat:MM-dd-yyyy"));
   var phoneContactDate = new Date(Application.FormatString
      (objPhoneContactDate, "date", "dateFormat:MM-dd-yyyy"));

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

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

   if (iNumberOfDays &lt; 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);

   // Now validate the phone contact and rep visit dates.
   if (!objRepVisitDate)
      return;

   var repVisitDate = new Date(Application.FormatString
      (objRepVisitDate, "date", "dateFormat:MM-dd-yyyy"));

   if (isNaN(repVisitDate))
      return;

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

   if (iNumberOfDays &lt; REQUIRED_REPVISIT_PHONE_INTERVAL)
      eventObj.ReportError(objRepVisitDate, 
         "The Representative Visit date must occur after " + 
         REQUIRED_REPVISIT_PHONE_INTERVAL + 
         " days from the start of the Phone Campaign.", false);
	
   // And finally, the email and rep dates.
   // Now check the Email Campaign start.
   iNumberOfDays = GetElapsedDays(emailDate, repVisitDate);

   if (iNumberOfDays &gt; REQUIRED_REPVISIT_EMAIL_INTERVAL)
      eventObj.ReportError(objRepVisitDate, 
         "The Representative Visit date cannot occur later than 
         Email Campaign Start date plus " + 
         REQUIRED_REPVISIT_EMAIL_INTERVAL + " days.", false);
}</code></pre></div><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Using the OnBeforeChange event</a></p><div id="ExpCol" class="collapsed" border="0"><p>The <b class="bterm">OnBeforeChange</b> event occurs after a change has been made to a field but before the change has been committed. When a user makes a change to a field and then leaves the field, the <b class="bterm">OnBeforeChange</b> event can validate the data the user entered
					 and reject the change before it is committed.</p><p>In the Events developer sample form, the <b class="bterm">OnBeforeChange</b> event validates the data entered in the Email Campaign Start, Phone Contact Start, and Representative Visit date fields. When a user enters a date in any of these fields, either by typing it or by using the Date Picker control, the <b class="bterm">OnBeforeChange</b> event occurs and the scripting code that it contains verifies that the dates entered or removed are in the correct order. If they are not entered in the correct order, the <b class="bterm"><a href="xdproReturnMessage.htm" id="HV01021325" lcid=" ">ReturnMessage</a></b> property of the <b class="bterm"><a href="xdobjDataDOMEvent.htm" id="HV01021239" lcid=" ">DataDOMEvent</a></b> object, which is the eventObj argument passed to the event handler, is used to set the text that will be displayed to the user, and the <b class="bterm"><a href="xdproReturnStatus_1.htm" id="HV01021327" lcid=" ">ReturnStatus</a></b> property is used to indicate that the change will not be accepted. The following example from the Events developer sample form shows the <b class="bterm">OnBeforeChange</b> event handler for the Email Campaign Start date field:</p><pre><code>function msoxd__EmailCampaignDt::OnBeforeChange(eventObj)
{
   // Ensure that the Phone Contact Date is not filled in already.
   if (XDocument.DOM
      .selectSingleNode('/Customers/CustomerInfo/ContactDates/EmailCampaignDt')
      .text == "" &amp;&amp; XDocument.DOM
      .selectSingleNode('/Customers/CustomerInfo/ContactDates/PhoneContactDt')
      .text != "")
   {
      eventObj.ReturnMessage = "Because you have entered a Phone Contact 
         Start date, the Email Contact Start date information cannot be removed.";
      eventObj.ReturnStatus = false;
      return;
   }
}</code></pre></div><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Using the OnAfterChange event</a></p><div id="ExpCol" class="collapsed" border="0"><p>The <b class="bterm">OnAfterChange</b> event occurs after a change has been made to a field and after the change has been committed. When a user makes a change to a field and then leaves the field, the <b class="bterm">OnAfterChange</b> event can validate the data the user entered or call other functions that can be used to update other fields within the form.</p><p>In the Events developer sample form, the <b class="bterm">OnAfterChange</b> event is used to call the CalculateTotalCampaignCost function. When a user enters a date in any of the date fields, either by typing it or by using the Date Picker control, and the data is committed, the <b class="bterm">OnAfterChange</b> event occurs and the scripting code that it contains calls the  CalculateTotalCampaignCost function, which calculates the total cost of the campaign and  updates the Campaign Cost field. The following example from the Events developer sample form shows the <b class="bterm">OnAfterChange</b> event handler for the Phone Contact  Start date field:</p><pre><code>function msoxd__ContactDates::OnAfterChange(eventObj)
{
   if (eventObj.IsUndoRedo)
   {
      // An undo or redo operation has occurred and the DOM is read-only.
      return;
   }
   CalculateTotalCampaignCost();
}
</code></pre><p><b>Note</b>  The <b class="bterm">if</b> statement used to check the <b class="bterm"><a href="xdproIsUndoRedo.htm" id="HV01021293" lcid=" ">IsUndoRedo</a></b> property of the <b class="bterm"><a href="xdobjDataDOMEvent.htm" id="HV01021239" lcid=" ">DataDOMEvent</a></b> object, which is the eventObj argument passed to the event handler, is automatically generated by InfoPath when the <b class="bterm">OnAfterChange</b> event handler is created. This statement can be used to handle a case in which the <b class="bterm">OnAfterChange</b> event occurs as a result of an undo or a redo operation.</p></div><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/inconDVEventsInEVTForm_l.htm"></iframe></span><center><a href="XMLSchemaCopyright_HV01147162.htm">&copy;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&amp;CTT=11&amp;Origin=HV011232471033" 

target="_new">http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp</a></center></body></html>