Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for form reset pattern #3100

Merged
merged 1 commit into from
Jan 7, 2025
Merged

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
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