Category: UI Widgets
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How to update table with input inside a list?

Issue

I am experiencing an issue with my app where the SQL update statement is only working correctly for the first item in a list with numeric inputs. When I update the input in any other item in the list, the updated value is always the first input. I am using the text property of the inputs to insert values into a table. Can someone help me fix this issue?

Resolution

The issue was that the SQL query was only considering the text input value of the first item in the list, and not the updated values for each subsequent item. The solution was to access the input value for each item in the list separately, using the index of the selected item.

The updated SQL statement is:

update team_league
set position = array[{{liga_teams_list.items[liga_teams_list.selectedItemIndex].input_position.text}}]
where league_id = {{liga_teams_list.selectedItem.liga_id}}
and id_team = {{list_teams_liga.selectedItem.id_team}}

This code will retrieve the input value for the currently selected item in the list, and update the corresponding row in the table. By accessing the input value using the selected item index and the name of the input widget, the correct value can be used for each item in the list when updating the table.