Resetting a Form
Often it’s desirable to reset a form after a successful submit. This clears all the form controls contained in the form to prepare it for new user input. A form can be reset by calling this.reset() where this refers to the form.
To specify code to run after a request has been sent and a response has been received, use the hx-on:htmx:after-request attribute. A shorthand name for this attribute is hx-on::after-request, which removes htmx from the middle.
For example, the todo app uses the following HTML form to provide a way for users to add new todos. Alpine (covered in the next chapter) is used here to store the value entered in the text input. This is needed so the Add button can be disabled when no text has been entered.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access