Wanting to update a record from a column panel

I created a repeating panel, with a Summary and Full Detail Part, if I click on the button it makes the drop down visible.

I thought it a great way to allow modification of that record, which it wont do sinceI bound all the rows in that to a data table row, and of course since there is rightly no client side access directly to the database,I get an error.

I’ve been reading the thread on creating a CRUD in Anvil Docs and it suggests creating a pop up. But I dont really want to do that as its not how the site is laid out.

My Question is: If I dont want the popup , how do I make it work? I can:-
a. Create a Dict from the Header Record
b. Populate a Repeating Panel from that Dict
c. Create a Save button that Creates an amended dict.
The record in question would be a repeating panel inside a repeating panel. Will the dict therefore update that record, or do I need to add a row ID so that the system will update the correct row.

Here is the bit of code that creates the dict and populates the update pop up.

  def edit_article_button_click(self, **event_args):
    # Create a copy of the existing article from the Data Table 
    article_copy = dict(self.item)
    # Open an alert displaying the 'ArticleEdit' Form
    # set the `self.item` property of the ArticleEdit Form to a copy of the article to be updated
    alert(
      content=ArticleEdit(item=article_copy),
      title="Update Article",
      large=True,
      buttons=[("Save", True), ("Cancel", False)]
    )

Here is an image of what I have

I notice that your alert has Save and Cancel buttons, which affect the alert function’s return value. You tell it to return True on Save, and False on Cancel.

But you’re not using that return value in any way. Consider,

  1. what do you want to happen in each case? And
  2. how would you code that activity, after the call to alert?
1 Like

Thank you for the information. I am going to go away and think more on this problem, I think if I cant get it doing what I want, I will do a clone of where I am at.
I’ve been advised that this would be the best way to get help and I agree, since I do sometimes struggle to adequately explain what I am trying to do.

I have similar situations.

  • A need to let someone edit some pieces of information.
  • But they may need to cancel the edit partway through.
  • If I give them the master copy of the variables, then, during the editing process, those will receive an incomplete set of changes.
  • So instead, I give them a copy (your article_copy), and Save and Cancel buttons.
  • On cancel, I just delete the copy (or, if it’s a local variable, just let Python clean it up for me, when the function returns). The master copy remains unaffected.
  • On save, I overwrite the master copy of the variables with their edited versions.

Details will vary with the situation, so there’s no one size fits all. But you’ve got a very good start on this.

1 Like

Update: Solved
I have now set up my update function this way, without the need for a popup:

  1. Created a Sub Form as a Component

  2. Added 2 Fields, one hidden, for each column I want updated on the table, like this:-
    1 x Label Field with the Data Binding - Label is hidden
    self.user_address_1.text = self.user['UserAddress1']
    1 x Text Fields which the Label Field Feeds the Data to, effectively creating a copy of whats on the database.
    self.label_address1.text = self.user_address_1.text

  3. I followed this tutorial on creating a refresh method and it works beautifully! Updating the main form with any changes made.

1 Like