Introduction to Openous Events and Scripting

Introduction to Openous Events and Scripting

Introduction

Each control in Openous can be programmatically manipulated through pure javascript. Since the native browser engine is used to interpret and execute the scripts and formulas specified by the user at design-time, the code is compatible with all browsers that support client scripting. 

Events

Depending on their type, Openous controls expose various events that are raised throughout their lifecycle, which can be handled by selecting the control in the Design area and clicking the “Events” tab in the properties panel on the right:
Events tab in Properties Panel

Typically, an event provides the developer with the necessary javascript variables/objects that contain all necessary info that accompanies this event. This info is contained within the “args” object and its properties. The “args” object inherits from the base <link: pf.IEventArgs>pf.IEventArgs interface, which contains two properties:
  1. Sender: the control that raised the event
  2. Parent: the related parent object of the event (usually the sender unless otherwise specified in certain cases)
Depending on the control type, the args object can also inherit from another interface (always child of base <link: pf.IEventArgs>pf.IEventArgs), and consequently contain other properties, specific to the event. For example, a Combobox (as well as any Data Control) exposes the ValueChange event, which is raised once the selected value of the combobox changes (either programmatically or by a user action). In this case, the required information needed by the developer to handle the event is not only the Combobox itself, but the previous value and new values. All of these are included within the “args” object, which in this case implements the pf.IValueChangedEventArgs interface, and exposes the following properties:
  1. args.Sender (inherited from pf.IEventArgs)
  2. args.Parent (inherited from pf.IEventArgs)
  3. args.Value: the new value of the control
  4. args.PreviousValue: the previous value of the control, immediately before the change
The following script example assumes that you have a combobox with “Country” items (with Code and Name properties), checks the newly selected country, and changes the value of another label named “lbl_SelectedCountryName” according to the selection:
        var country = args.Value; //this is an object, since we have single select combobox
        var lbl = form.GetControl("lbl_SelectedCountryName");
        if (country.Code == "USA")
            lbl.SetValue("You have selected United States!");
        else
            lbl.SetValue("You have selected a country outside U.S.");

Notice how apart from the “args” object, the “form” variable is also available for providing a shortcut to the parent form container (class: pf.Form) . This is extremely useful if you want to manipulate other controls within your script, or reference properties and methods that are form-wide (for example the underlying DataItem property that refers to the List Item that is displayed in your form).