-
Notifications
You must be signed in to change notification settings - Fork 57
Open
Description
In the chapter on using htmx to send the email to the server to surface validation errors prior to form submission:
the email of the contact gets set on the Contact.db
and does not get revered to the original state. The effect is that if the user navigates back to the list view, they will see duplicated emails. See video:
Apr-02-2024.09-29-15.mp4
I thought maybe I messed up the htmx and was calling a POST or PATCH somewhere unexpectedly. Instead it was just mutating the dummy db
. I was able to fix with this updated handler:
@app.route('/contacts/<contact_id>/email', methods=['GET'])
def contacts_email_get(contact_id: int):
contact = Contact.find(contact_id)
# Temporarily store original email
old_email = contact.email
contact.email = request.args.get('email')
contact.validate()
# Restore email to previous value
contact.email = old_email
return contact.errors.get('email') or ''
P.S. Thanks for the book!
dharmatechgeophpheriekartikynwa
Metadata
Metadata
Assignees
Labels
No labels