10.4. Events In our previous example, we associated a script function with a button, so that every time the button was clicked, the script function was executed. There are a number of different kinds of events that trigger script execution in addition to the clicking of a button. They include positioning the cursor on a field, changing a value, loading a form, switching views, and more. The InfoPath events are listed in Table 10-1. Table 10-1. Types of events Event type | Description | OnClick | The user clicks a button on the form. | OnBeforeChange | The user changes the value of a field (before the change is accepted). | OnValidate | The value in a field is validated, after it is changed. | OnAfterChange | The user changes the value of a field (after the change is accepted and validated). | OnLoad | A document is opened with the form. | OnSwitchView | The user switches views. | OnAfterImport | The user queries the data source to import new data. | OnSubmitRequest | The user submits the form. | OnVersionUpgrade | The user opens a document that was created using an older version of the form. | A script function may be associated with a particular event, and in some cases a particular field or button. In the script, the name of the function will indicate the event. For example: -
A function named CTRL1_5::OnClick will be executed when the CTRL1_5 button is clicked. -
A function named msoxd_item_number_attr::OnValidate will be executed when the item number field is validated. -
A function named XDocument::OnLoad will be executed when a new document is loaded. You don't have to specify these function names yourself. They are generated by XPath when you launch Script Editor and they should not be changed. However, it is useful to understand their meaning when editing the script. Throughout the rest of the chapter, we will see examples of working with these events. |