Databinding Question

I updated the CRUD Form example above so it has the company values in your screenshot. Does this help?

https://anvil.works/build#clone:HTH2R4L6LF7TEWD2=VKTGUCXF4ULYQKUCHGKTV3D6

The technical cause of this error is that the expression app_tables.company_info.search(Email=anvil.users.get_user()['email']) resolves to True even when the search method returns no results. But then the get method returns None (so line 43 is trying to assign something to None['Company_Name']).

More broadly, though, the reason that several folks are trying to help you by pointing you to tutorials and asking you more fundamental questions rather than giving you specific suggestions is that, to put it bluntly, a line like company_info['Company_Name'] = self.company_name_textbox.text doesn’t make any sense. I may be misinterpreting your intentions, but you seem to think that line will “pull the data and assign it to” that textbox field, but its actual meaning is the reverse: to pull from the textbox and assign that value to the data table field. In any case, such a line is redundant to the data binding that already connects that textbox to the data table field. So your code seems to reveal a lack of understanding of how this stuff works. You may need to take a step back and do some Python/Anvil learning before returning to building your app.

My suggestion is to work slowly through one of the tutorials others have pointed you towards, fiddling around with it and looking up things in Python and Anvil docs to make sure you understand what’s going on. Then try it out from scratch in a simpler version of your app–remove all the other stuff and just try to get data binding to work on a single text box (something like the example app @nickantonaccio has kindly provided for you)–and get that working. Then return to your more complex app and implement it there.

4 Likes

You are right. I have to take a few steps back and get some of the basics down again. I thought I had what I needed to make sense of the Anvil System. However, I was mistaken.

I figured the forums here would help guide me in the right direction since my questions are specific and different than what was in the docs. (Or I could have missed something again possible),

I am going to take what @nickantonaccio has provided graciously and figure it out.

2 Likes

There are just a few things to focus on to clear up your questions.

First, this line gets a reference to a row in the data table, where the ‘company_name’ field equals the selected value in the dropdown widget:

row=app_tables.table_0.get(company_name=self.drop_down_1.selected_value)

Then each of these lines just pick values from the specified columns in that row, and assign those values to the .text property of specified widget on the page. Think of row[‘item’] like a dictionary (it’s not - it’s an object which holds a references to values in the selected row, but the syntax works similarly):

    self.text_box_company_name.text=row['company_name']
    self.text_box_admin.text=row['admin']
    self.text_box_email.text=row['email']
    self.text_box_phone.text=row['phone']
    self.text_box_address.text=row['address']
    self.text_area_representatives.text=row['representatives']

Then these lines just set values in the specified columns of the selected row, to the string stored in the .text properties of the specified widgets:

      row['company_name']=self.text_box_company_name.text
      row['admin']=self.text_box_admin.text
      row['email']=self.text_box_email.text
      row['phone']=self.text_box_phone.text
      row['address']=self.text_box_address.text
      row['representatives']=self.text_area_representatives.text

Hopefully, that helps clarify your fundamental question.

1 Like

@nickantonaccio This is exactly what I was trying to figure out how to do. I went through the clone app you provided and it answers my question. I just have to figure out how to load the information for each specific user.

I want to thank you again for all your help. This makes 100% sense to me as to how to assign a row to a textbox now. I wish Anvil documentation had this type of example which can clarify so many things.

Again Appreciate all your help.

1 Like

The Anvil tutorials have those sorts of examples, and more. Don’t limit yourself to just the documentation, which is intended to be more reference than tutorial.

3 Likes

I agree @jshaffstall . That is where my lack of experience comes from. I am only a beginner in coding, and learning python as I learn to code my project. I youtubed a lot hehe and skimmed through the tutorials.

Nick was exceptionally helpful by taking my example and making the references to what I needed. I took his example and easily modified functionality. He used dropdown and I automatically pulled the info from the user’s email.

I just know I wouldn’t have figured it out without the help of @nickantonaccio. Truly made my day as i learned something new and got my app to work the way I intended.

1 Like