Hello,
I have a table with one column:
A
B
C
And a drop.down list displaying this column
When I select A from drop.down list i want to update this value with another value D from a texbox.
I read a post here related to update value from datatable, but not exacly what i want, because the example refers to another column. I want the selected value to change.
Thanks
To clarify:
When someone selects A, you want to change the actual selected value to D?
Yes, this is what I wants, when someone selects A, I want to change this value with the textbox text after pressing a button.
I used this code:
self.drop_down_1.items = [(x[‘Name’],x) for x in app_tables.client.search()]
def button_save_changes(self, **event_args):
column_to_edit = self.drop_down_1.selected_value
row1 = app_tables.client.get(Name=column_to_edit)
new_value = self.text_changename.text
row1[Name]=new_value
I tried but I have this error:
anvil.tables.TableError: Column ‘Name’ can only be searched with a string (not a Row from ‘client’ table) in table ‘client’
Just to check, that error occurs in which line? The above line?
I don’t know, it doesn’t show the row of error.
Actually, it does. When you run your app in anvil’s IDE, error messages like these usually appear in the Output panel. If you read the message shown there, carefully, you’ll find that it includes many helpful details.
To see how you can look at your own Output panel, see Anvil Docs | The Anvil Editor .
To sum up:
The table nane is: client
The column nama is: Name
I have a table with one column:
A
B
C
And a drop.down list displaying this column
When I select A from drop.down list i want to update this value with another value D that someone write in a texbox using a button to save changes.
I used this code:
self.drop_down_1.items = [(x[‘Name’],x) for x in app_tables.client.search()]
def button_save_changes(self, **event_args):
column_to_edit = self.drop_down_1.selected_value
row1 = app_tables.client.get(Name=column_to_edit)
new_value = self.text_changename.text
row1[‘Name’]=new_value
Error description is:
anvil.tables.TableError: Column ‘Name’ can only be searched with a string (not a Row from ‘client’ table) in table ‘client’
I think the error is in this line because I am searching the row and not the value
Anvil detects the error further below, but you are right, this is the cause of the error.
For more detail, see the docs of the Dropdown component. But essentially, when you fill in the dropdown’s items
, you have two ways to do it:
- with a list of single
str
s.
- with a list of two-element
tuple
s.
Each option gives you a different selected_value
.
It looks like you wanted option 1.
I am so sorry, I haven’t seen the entire message. And you are right the error is related to the row you highlighted.
No worries here.
Every tool takes getting used to, including Anvil’s App Editor.
How can I turn this into a string
from your code above you don’t need to do app_tables.client.get(Name=column_to_edit)
you should replace the variable name column_to_edit
with row_to_edit
You already have it…
This came from the line
self.drop_down_1.items = [(row[‘Name’], row) for row in app_tables.client.search()]
When your user is selecting something from the dropdown - the selected_value
is the row (the second item in the tuple)
The display value is x['Name']
- (the first item in the tuple)
1 Like