hub.eb?material_id=379&track_id=368

Form-Component Programming Interaction


Forms can access Fields, Tables, Resources, Controls etc. of a contained Component via the components interface and vice-versa using the form interface. These operations are collectively known as Form-Component Interactions.

A Form can access a Component it contains via the components interface. Each Component can be accessed using it's prefix via components.getComponent(prefix) or directly using components.pfx_myComponent (where the instance of the Component, myComponent, has the prefix pfx). You may wish to customise a component from a form it is being displayed on e.g. setting a page title or a menu breadcrumb.

A Component can access a parent Form using the form interface. This interface returns an object representing the Form.

Steps


1

Create a new Part-page Component named myComponent.

2

Add a Text Control, named myComponentText, and a Button to the component. Set the Button text to Click from Component.

3

Add a new On Click event script to the Button with the following code:

form.controls.myFormText.text.setText("Set from the Component");
4

Create a new Form and add the Component to it. You can do this by right-clicking in the Outline view and selecting Add control to Page > Part-page Component. Set the Component prefix to pfx_.

5

Add a Text Control to the form and name it myFormText.

6

Add a Button to the Form and give it the text Click from Form. Add an On Click event with a new script to the button:

components.pfx_myComponent.controls.myComponentText.text.setText("Set from the Form");
7

Run the Form. Clicking the Form button will set the value of the Text Control in the Component. Clicking the Component button will set the value of the Text Control on the Form.

Current Module

Related