Synchronize a UX Component with an Embedded UX Component

Description

For a video explanation of this subject watch this video.

Creating a Child UX With Arguments

This section will focus on creating the Component to be embedded in a parent UX Component. A defined 'Argument' in the embedded component will be used to synchronize it with the parent.

  1. In the UX Builder on the UX Controls page. Open the 'Data Controls' menu and click on [List] to add a list control to the component.

    images/child.png
  2. In the properties list click on the button next to the 'List properties' property in the List Properties section.

    images/child2.png
  3. In the List Builder's Data Source pane set the 'Data Source Type' to be SQL.

    images/child3.png
  4. Set the 'Connection string' property in the SQL Data Source section to be the 'Northwind' database.

    images/child4.png
  5. Set the 'Table name' property to the 'Orders' table.

    images/child5.png
  6. Click the button next to 'Field list' property. Select the OrderID, CustomerID, EmployeeID, and OrderDate fields.

    images/child6.png
  7. Click on the button next to the 'Arguments' property in the Arguments section.

    images/child7.png
  8. Click the 'Insert New Argument' button. Create a new argument named 'whatcustomerId'.

    images/child8.png
  9. Set the 'Value' property to be alfki. This references the CustomerId field. You will need to type this is to the property textbox. Click OK.

    images/child9.png
  10. Click the button next to the 'Filter' property in the SQL Data Source section..

    images/child10.png
  11. In the 'Target Fields' list double click on the 'CustomerID' field to add it to the filter.

    images/child11.png
  12. Click the '=' button.

    images/child12.png
  13. Click on the 'Insert Argument' button. Select the 'whatcustomerId' argument. Click OK

    images/child13.png
  14. Open the 'List Layout' pane. Use the blue > arrow to move the OrderID, CustomerID, EmployeeID, and OrderDate fields from the Available Fields list to the Columns in List. Click OK to close the List Builder.

    images/child14.png
  15. Open the 'Data Controls' menu. Click the [TextBox] option to add a text box control underneath the list control.

    images/child15.png
  16. Highlight the textbox control. In the properties list on the right find the 'Default value' property under the Field Properties section. Set this to the following:

    =:whatcustomerId
    images/child16.png
  17. Save the component as 'child_ux' and run it in Live Preview. You should only see 'ALFKI' displayed in the CustomerId field. Close the component.

    images/child17.png

Embed the Child UX Component in a Parent Component

  1. From the Web Projects Control Panel create a new blank UX component.

    images/embed.png
  2. Open the 'Other Control' menu and click on the [Embedded Object] control.

    images/embed2.png
  3. From the Object Name list select 'child_ux' and click OK

    images/embed3.png
  4. Save the component as 'parent_ux'

    images/embed4.png
  5. Run the component in Live Preview, you should see the child ux displayed.

    images/embed5.png
  6. Return to the Design tab.

    images/embed6.png

Synchronize the Child List Control with the Parent.

  1. In the 'parent_ux' component's UX Controls page open the 'Data Controls' menu. Click on the [DropdownBox] option to add a dropdown box to the component. Use the blue up arrow in the toolbar to position the dropbox above the embedded object.

    images/synch.png
  2. Highlight the Embedded Object.

    images/synch2.png
  3. Open the Containers menu and click on [Frame]. Select 'Insert Around' to place the Frame around the Embedded Object control.

    images/synch3.png
  4. Highlight the Embedded Object. In the properties list's Component Definition section set the 'Component alias' property to be 'UXCHILD'.

    images/synch4.png
  5. Click on the button next to the 'Argument bindings' property, also in the Component Definitions section.

    images/synch5.png
  6. Highlight 'whatcustomerId' and click the 'Set Argument Value' button.

    images/synch6.png
  7. Click 'Insert Fields Placeholder'. Set the argument value to be the drop-down box you defined, dropdownbox1. Click OK and OK again.

    images/synch7.png
  8. Highlight the dropdown box control.

    images/synch8.png
  9. In the properties list under 'DropDownBox' Properties click the button next to the 'Choices' property.

    images/synch9.png
  10. Select 'Dynamic'.

    images/synch10.png
  11. In the Define Choices dialog go to the 'Data Source' section. Set the Data source type to 'AlphaDAO'.

    images/synch10.png
  12. Set the 'AlphaDAO Connection string name' property to be the 'Northwind' database.

    images/synch11.png
  13. Click the button next to the 'AlphaDAO SQL SELECT statement property.

    images/synch12.png
  14. In the SQL Select dialog click the 'Select' button and set the Table to be 'Orders'.

    images/synch13.png
  15. From the 'Field to display' dropdown select 'CustomerID'. Click OK and OK again to close the Choices dialog.

    images/synch14.png
  16. Scroll down the drop-down box's properties list to the 'Javascript' section. Click the button next to the 'onChange' property.

    images/synch15.png
  17. Click the 'Add New Action' button.

    images/synch16.png
  18. In the Categories list of the 'Select an Action' dialog choose 'UX Component'.

    images/synch17.png
  19. Scroll down to the bottom of the Actions list and click on 'Refresh/synchronize embedded UX component. Click OK

    images/synch18.png
  20. This action should show an 'Embedded UX Component' property. From the dropdown for this property select 'UXCHILD'. Click OK.

    images/synch19.png
  21. Save the new action.

    images/synch20.png
  22. Run the parent_ux component in Live Preview.

    images/synch21.png
  23. Whenever the Dropdownbox is updated you should see the child_ux respond by updating the list control. The Child textbox control, however, is not yet synchronized.

    images/synch22.png

Synchronizing the Child's Textbox control.

In order to synchronize the textbox control it is necessary to make use of Alpha Anywhere's Client-side and Server-side Events.

  1. Open the child_ux component in the UX Builder.

    images/text.png
  2. Open the Client-side Events page. In the Client-Side Events list highlight the onSynchronizeDialog event.

    images/text2.png
  3. Add the following alert to the onSynchronizeDialog event. This will tell you when

    alert('client side synchronize');
    images/text3.png
  4. Open the Server-side Events page. Highlight the onSynchronize Event in the Server-Side Events list.

    images/text4.png
  5. Add the following code inside the onSynchronize function definition

    dim newval as c
    newval = argval(e.arguments, "whatcustomerid")
    e.javascript = "{dialog.object}.setValue('textbox1','"+js_escape(newval)+"');"
    images/text5.png
  6. Save the Child component.

    images/text6.png
  7. Reopen the parent_ux component and run it in Live Preview. When the dropdown box is updated both the list and the textbox should update as well.

    images/text7.png