What I’m trying to do:
I’m a complete beginner to Anvil so excuse my ignorance if this is something very basic!
I have a stage in my app in which I’m aiming to have this flow:
- User clicks a button
- External API is queried to get a list of values
- An alert is initiated, with displaying a radio group with the list of values
- User chooses an item and clicks ‘Save’
- The chosen value is added to a data table
What I’ve tried and what’s not working:
Steps 1 and 2 are working fine, but it’s the rest I’m struggling with. I’ve completed the basic 3 tutorials, so I chose an approach using alerts (similar to the ArticleEdit alert in the news app tutorial), which contains a repeater panel. Each repeater panel part contains a single radio button, and I give this a name and a value from the item - this works correctly and when I open the alert I can see a radio list with all the items and values. The place where I’m stuck is saving this capturing the chosen value - so far I’ve tried assigning the selected value to a variable named selected in the parent, so that I can use it when “Save” is clicked, however the value does not seem to make it to the parent:
Used in the code of the repeater panel template:
def account_radio_clicked(self, **event_args):
"""This method is called when this radio button is selected"""
if self.account_radio.selected:
self.parent.parent.selected = self.item
Used in the form that the alert is generated from.
def choose_account_button_click(self, **event_args):
accessible_accounts = anvil.server.call('get_accessible_accounts')
selected_account = {}
link_clicked = alert(
content=GASelectAccount(accounts=accessible_accounts, selected=selected_account),
title="Choose Project",
large=True,
buttons=[("Link", True), ("Cancel", False)],
)
if link_clicked:
print(selected_account)
I’m unsure if this is the correct to approach to go down, to create a radio input on a form, and if so where I’m going wrong in the code.
Any help or guidance on this would be much appreciated!