Working with controls in scripts

Newlook supports a wide range of controls that you can add to your forms with Designer. To create a truly dynamic UI, scripting or macros are required to:

Control Naming

To reference a control accurately in a script, it is recommended that you name the control in Designer. It is also possible to reference a control using the Form.ActiveControl object or its index in the Controls Collection, however both of these methods are less accurate than using a control's name.

Event Handling

Newlook controls trigger different events. If you would like some custom behavior to happen as a result of an event, you can have Newlook call your script every time the event occurs. To connect a script to an event, do the following:

  1. Open the relevant form in Designer (unless you are already in Designer).
  2. Click on the control who's event(s) you want to handle.
  3. Bring up the Properties window for that control unless it is already up by right clicking on the control and selecting Properties Window (F4).
  4. Scroll down to the Events category and have a look at all the events available to be handled for this control.
  5. Set the event property that you wish to handle to the name of the relevant script.
  6. Save your override.

Step by Step Example

This is a simple example that demonstrates the concepts of Control Naming, Event Handling and using scripts to interact with controls.

A. Create a new form and place some controls on it:
  1. Create a new form by selecting Forms | Added Forms | New from the Developer Bar.
  2. Insert a checkbox control on the form. Change the caption of the checkbox to Extended list.
  3. Set the OnChange property to ModifyList.
  4. Set the Name property to extendedList.
  5. Next insert a combo box control on your form, below the checkbox.
  6. Set its name to Items.
  7. Set its List property to A;B;C;.
  8. Save the form with the name Item Selection.
B. Create a script to open the form.

Now that the form is saved, we need to create a script that opens the form using the OpenForm method.

  1. From the Developer bar, select Logic | Scripts, then click New.
  2. In the properties panel of the script editor enter the name OpenItemsForm and select JScript from the language drop down.
  3. Expand the Menu section and tick the option Show in the menu for smartclient users.
  4. In the main script editor window enter the following one line script and save the script:

App.OpenForm ("Item Selection");

C. Create the script to handle the OnChange event of the scrollbar.
  1. Open a second new script and give it the name ModifyList.
  2. Select JScript from the language drop down.
  3. In the main script editor window enter the following lines of code and save the script:

if (App.ActiveForm.extendedList.Value == true)

{

App.ActiveForm.Items.AddItem ("D",3);

}

else

{

App.ActiveForm.Items.Clear;

App.ActiveForm.Items.List = "A;B;C;";

}

Open the runtime client and run the OpenItemsForm script from the macro menu. The combo box list should vary between four items and three, depending on whether you have the extended items checkbox selected or not.


© 2004-2021 looksoftware. All rights reserved.