Crash Course 101
10 modules
5 weeks

Relselect

Click to copy

How to use Relselect component


Now, by analogy, you can make a page for the list of cities. The only important difference is that when creating a city, the country in which it is located must be selected.

Relselect component

The Relselect component is suitable for implementing this feature. It allows you to select from a list of data already entered into the database. Let's look at this with an example.

Adding the Relselect component starts the initial setup procedure for it. It is necessary to select the data source (we are interested in the list of countries, so we select the Country model), the display field (the name is the most logical option, although you can choose any other), and the Single or Multiple modes (the city can only be in one country, so we select Single).


The next step is to get a list of countries that will be available for selection. This process is similar to what was needed to display data in a table. Remember that initially, any component is empty, and to obtain data, you need to make an appropriate request to the database.

Let's use the onCreate trigger to run immediately at the moment the component is created, execute a database query using the Server request GET /Country/ block and add the received data with the RelSelect Update Properties block.


The list of countries becomes available for selection. It remains only to find out the selected value and save it when adding a new city. You need a RelSelect Get Properties block and its Selected output parameter to do this.


If everything was done correctly (and the _with parameter was used when receiving data), then now the list of countries also contains information about which cities are located in it.


Was this article helpful?
Still looking for an answer?
Join the Community