Hi there, I’m having trouble allowing a user to edit his or her own account info, here’s the situation…
On the page of the app that lists the users account info, I’ve got 3 text boxes, displaying the users first name, last name and company.
When the Edit button is checked, the text boxes enable and they can accept user input, uncheck it again and they disable…
I want whatever text the user types in here to update the corresponding field on the corresponding users row in the User data table.
Here’s my code so far…on the client side…
…and on the server side…
The app currently throws this error when I try to input any test into the first name field:

Thank you in advance for any help you can provide! -Ian
When you assign “new_first_name” my guess is it’s returning “None”.
Are you meant to be setting it to the text? If so you need :
new_first_name = self.text_box_user_first_name.text
instead of “select()”, which just highlights the text in the box.
Also, are you intending to save changed details when the check box is unselected?
If so, you don’t need to listen to the change event on the text boxes as this will fire with every key press. You just need to check the change event on the checkbox, and if it is unselected send all your text boxes to the server for saving. Personally, though, I would have a “save” button to make saving an explicit action.
Does that make sense?
Thanks David, it does make sense, and I do like the addition of the Save button.
It’s almost working now, it’s not throwing an error, but it’s still not writing to the Data Table…here’s what it looks like as you use the components…
…tick edit, it disappears…
…input name…
…hit Save…
Here’s the client code
and server code
I suspect the server call may be the issue now. Thanks for taking a look! -Ian
I’ve found it extremely helpful (for the user, and for tech support), to always pair a Save button with a Cancel button. This makes it possible for a user to explore all sorts of options, with the explicit assurance that any accidental changes (noticed or unnoticed) cannot pollute their earlier efforts.
1 Like
What do you program the Cancel button function to do, break the Save button function? (for lack of a better term)
I would make it put the old data back into the boxes and “uncheck” your check box to disable the boxes.
Regarding your updating the data - the server function doesn’t update anything. It appears to just return a client view, which I don’t think is what you want.
You need to do something like this under the if statement :
current_user.update(first_name = new_first_name)
I’m guessing you were following the documentation example here for client writeable views :
https://anvil.works/doc/index.html#-div-id-data_tables_views-exposing-data-tables-to-client-code-div-
What that did was return a search result to the client side, the parameter was the search term not a new value to save.
current_user.update(first_name = new_first_name)
this worked great, thanks! -Ian
2 Likes