Choose One Value from a List
In some situations, instead of typing a value, we want end-users to choose that value from a list of predefined values. In OutSystems, implement this using a Dropdown widget (in mobile apps) or a Combo Box widget (in web apps).
In a mobile app:
- Drag the Dropdown widget from the toolbox into the form.
- Set the List property with the list of values to display in the Dropdown.
- In the Values property, select the attribute that identifies the displayed values.
- Set the Variable property with the variable that will hold the chosen value.
- In the widget tree, inside the Dropdown, set its expression with the value to display.
In a web application:
- Drag the Combo Box from the toolbox into the form.
-
Feed the Combo Box in one of two ways:
Through a List:
- Set the Source Record List property with the list of values.
- In the Source Attribute property, select the attribute to display in the list.
Directly from an Entity:
- In the Source Attribute property, select the attribute to display from the entity.
- Set the Source Entity property with the entity with the predefined values to display in the Combo Box.
-
Set the Variable property with the variable that will hold the chosen value.
Example in a Mobile Application
In the GoOut app, a mobile application to find and write reviews about places, we want to allow end-users to write reviews about new places. In these cases, the WriteReview screen will show three extra inputs for the new place:
- Name
- Category
- Address
The category is a list of values, so we will implement it with a Dropdown widget. We will use the GetCategories aggregate to get all categories:
- Open the WriteReview screen.
- Drag the Dropdown widget from the toolbox into the form, and drop it between the name and address inputs.
- Set the List property to the list of categories
GetCategories.List
. - Set the Values property to
Category.
Id
to define the identifier of each value in the Dropdown. - Set the Variable property to
Place.CategoryId
. - In the widget tree, inside the Dropdown, set its expression to
GetCategories.List.Current.Category.Label
. - Publish and test.
Example in a Web Application
In the GoOutWeb app, the web version of the GoOut app, we want to set the place category when editing it. We have the Category static entity that holds all categories:
- Open the PlaceEdit screen.
- Drag the Combo Box widget from the toolbox into the form.
- Set the Source Entity property to the Category static entity.
- Set the Source Attribute property of the Combo Box to
Category.Label
to display the label of each category. - Set the Variable property to the place category:
PlaceForm.Record.Place.CategoryId
. This property specifies the variable that will store the value selected by the end-user in the Combo Box. - Publish and test.