What's the "Selection Field" Used for?
The "Selection Field" of an array is mappable to any integer field (which is outside of the array). The integer field mapped to the Select Field (row-id in below screenshot) holds the index of the row the user has selected.
A row in the array is "selected" when the user is editing a field in that row or has clicked a Process Button from that row.
The indexing starts with 0 and increments from there.
For example, below the Selection Field has a value of 0 because the first row in the list is selected.
Position Calculations
Almost always, you'll utilize the "Selection Field" in position calculation(s). By doing this, you can get the last selected value or the value at a row from which a button was clicked.
Click the red "1__2__3__" to the left of "list-item" to set a position calculation.
Oftentimes, the position calculation is simply a reference to the Selection Field using the basic "field" calculation.
Example: Configure a Selection Field
Add an Integer Field (row-id)
Add a new integer field to the form and name it row-id. You do not need to make any other modifications to this field.
Add a List Field
Underneath the row-id field, add a list (array) from the Data Groupings section.
Add Fields in the List
In this example, an integer field and a field State were added. This will make more sense as you keep reading.
Add Some Data to the List
This step is only for demonstration purposes. To set up some data in the list, we'll initialize the list from a data table, so there are some values in the list.
Set the "Selection Field"
In the Control Properties, set the "Selection Field" to be the integer row-id field that you previously created.
For example, use the current-position-one-based dropdown to calculate the current position of a row. If we wanted the current position to start at zero, we could simply use current-position.
Test
To test this, I want to switch from design to preview mode. Once I click into the preview, I see 5 records.
Below is what happens when I click on the first row in the list. I can clearly see that the value of the row-id changed to 0. This is because we currently have the first item of the array selected.
The first item in the array has an index of 0 (not 1), and the index increments from there.
See how row-id updates based on the row you're editing:
Use the Selection Field in a Position Calculation to get the Selected State
Now, add a string field to the form and we'll configure it to hold whatever is the value of the State in the currently selected row.
We'll configure an update calculation on the string field:
The calculation needs to be an if statement and the expression needs to check if the Selection Field (row-id in our example) has a value.
For the then statement, choose a basic "field" calculation.
In the Field Browser, click the red "1__2__3__" to the left of the list item (group-3 in this example):
A "Position" dropdown will appear. Select "calculation".
For longer forms, the list might scroll and you may need to scroll up/down to get back to the Position dropdown.
After you select "calculation", an integer calculation pop-up will appear.
Change this to the basic "field" calculation and select the Selection Field (row-id in this example).
Click OK, which will take you back to the Field Browser.
Select the field in the array which you want to capture (State in our example).
Click OK, which will take you back to the original calculation. It should look like this:
Test it in Preview and see how the selected-state field updates as you select different rows: