Skip to content

Conversation

rkilpadi
Copy link
Contributor

@rkilpadi rkilpadi commented Jan 1, 2025

Description

Improved documentation and added example on form reset pattern as requested in the following issue.

Corresponding issue: #1698

@geoffrey-eisenbarth
Copy link
Contributor

geoffrey-eisenbarth commented Jan 4, 2025

As part of PR #3094, the following alternative would also work:

<form hx-target="#notes" hx-swap="afterbegin">
    <div>
        <label>Add a note</label>
        <input type="text" name="note-text" placeholder="blank canvas">
    </div>
    <button type="reset" hx-post="/note">Add</button>
</form>
<ul id="notes"><!-- Response will go here --></ul>

EDIT: I originally didn't see the part about only resetting on successful requests which my example doesn't handle

@rkilpadi
Copy link
Contributor Author

rkilpadi commented Jan 5, 2025

As part of PR #3094, the following alternative would also work:

Good point, that would probably work for the example used in the issue. I do think resetting only on successful requests is an important stipulation, though (we wouldn't want to reset a username on failed login, for example). This method also can be extended to elements that aren't forms. Maybe "reset user input" would be a better name.

@Telroshan Telroshan added the documentation Improvements or additions to documentation label Jan 7, 2025
@Telroshan Telroshan linked an issue Jan 7, 2025 that may be closed by this pull request
@Telroshan Telroshan merged commit 5f3cb58 into bigskysoftware:master Jan 7, 2025
1 check passed
oliverhaas pushed a commit to oliverhaas/htmx that referenced this pull request Jan 28, 2025
emilhem pushed a commit to emilhem/htmx that referenced this pull request Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document form reset pattern
3 participants