Creating the Component foundation: controls, arguments, Events, and simple functions
- Create a new, blank UX Component.
- Define a data series of the first letters of the companies in the Customers table:
- In the Design left-side panel, click Properties.
- In the Properties pane, locate Data Series. Add a new Data Series.
- Enter the name FirstLetters.
- Edit the series definition. In the Data Series Builder window:
- Data Source Type: SQL.
- Define the SQL Data Source as shown here:
- Click OK to exit the Data Series Builder.
- Add a Slider control for selecting a letter of the alphabet (which will be the first letter of a company’s name), and assign the following Properties values to the control:
- Name: letterSlider.
- No Label.
- Position (for Label): None.
- Default value: A.
- Under Slider Properties – Slider data type: Character.
- Method for specifying values: DataSeries.
- Data series mapping: Choose the data series FirstLetters, and for the Sub-series choose Index.
- Mark the checkbox for Show slider message.
- For the Slider message, enter Company starts with, and then the placeholder {value}.
- Slider message style: In the Style Editor, set Text Alignment to center.
- Slider message position: Above.
- Save the Component with the file name RevenuePieChart.
- In the Design left-side pane, click Properties, and define an argument to use a value from letterSlider to look up companies:
- Argument name: whatLetter.
- Data type: Character.
- Choose Set value at Run-time.
- Value: {letterSlider}.
- After letterSlider, add a Textbox control to temporarily store and display a company’s CustomerID field.
- Name the control customerIDHolderBox.
- Define a dynamic Data Series of companies whose names begin with the value in the argument whatLetter. Defining a Data Series at Component level makes it available to all controls in a Component:
- In the Design left-side panel, click Properties.
- In the Properties pane, locate Data Series. Add a new Data Series.
- Enter the name companyNameSeries.
- Edit the series definition. In the Data Series Builder window:
- Data Source Type: SQL.
- Define the SQL Data Source as shown here:
The complete SQL statement is:
SELECT CompanyName, CustomerID
FROM Customers WHERE Left(CompanyName, 1) = :whatLetter
ORDER BY CompanyName
- Click OK to exit the Data Series Builder.
- Save the Component.
- Add a Spin List control that will display the companyNameSeries:
- Name companyNameSpin.
- No Label.
- Method for defining list: DataSeries.
- Data series mapping:
- Display value: companyNameSeries.CompanyName.
- Stored value: companyNameSeries.CustomerID.
- Un-mark Add blank item to list.
Along with the instructor, define an Action for the Spin List.
- Define a function to verify that the user stopped moving the Spin List:
- For the Spin List, click OnSelect.
- In the script window, enter the following 4 lines (the second line is broken here, but not in the script window):
setTimeout(function() {
{dialog.object}.setValueFrom
'customerIDHolderBox','companyNameSpin');
//line above divided to fit in margins
} , 300
)
Observe Alpha Anywhere’s script prompting.
What do the parts of the script mean?
- setTimeout( – a standard JavaScript method that has one function wait before proceeding with the next. It has two arguments: the function, and the number of milliseconds to wait.
- function () – the method must call a function.
- { – the JavaScript delimiter for the opening of a function.
- {dialog.object}. – the current UX component. It is enclosed in { } because Xbasic eventually evaluates it.
- setValueFrom – an Alpha Anywhere JavaScript method. Its two parameters are in ( ). To see a list of Alpha Anywhere JavaScript methods, click Insert UX Component method… below the script window.
- } – closes the function parameters.
- , 300 – time to wait, in milliseconds.
- ) – closes the setTimeout method.
Continue working along with the instructor on the next Action and controls.
- Define an Action so that letterSlider changes the values in companyNameSeries in companyNameSpin using the argument whatLetter:
- Click on letterSlider.
- In its Properties pane, click OnChange event.
- In the script window, enter the following (all on one line, no spaces):
{dialog.object}.refreshDataSeries ('companyNameSeries');
When “current UX Component” (letterSlider) changes, refresh
companyNameSeries.
- Click OK.
- Next to companyNameSpin, add a Button control that will (eventually) look up the orders and chart them as a percentage of total sales. For the Button text, enter Show the chart.
- Below companyNameSpin and the Button, add a Container control where we will place the chart. Change the Container Id to CHARTCONTAINER.
- In CHARTCONTAINER, add a Static Text control. For its Static text, enter the following (all on one line, no spaces):
<div id="CHARTS" style="width:600px;height:600px;"> Refresh your browser.</br>Google API failed</div>
- This demonstrates use of HTML in a Static Text control.
Now you finish the previous page’s tasks on your own. Then:
- Define an argument we will use to look up a company’s rows in the Orders table:
- Argument name: whatCustomerID.
- Data type: Character.
- Choose Set value at Run-time.
- Value: {customerIDHolderBox}.
- Enclose all of the Component’s controls in a Panel Card control.
- Save the Component, and display it in Working Preview.