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

hx-swap="delete" should be allowed to work even with no request at all #2714

Open
mlncn opened this issue Jul 12, 2024 · 1 comment
Open

Comments

@mlncn
Copy link

mlncn commented Jul 12, 2024

The documentation on swapping says that for delete, hx-swap "deletes the target element regardless of the response"

While #1130 has raised the issue of this not happening for 204 response codes, i think it should go further— if hx-target and hx-swap="delete" are set, the target should be deleted even if none of hx-get, hx-post, hx-put, hx-patch, or hx-delete are set.

Current use case is loading the full size of an image and then, to remove it, deleting it entirely. Of course JavaScript can do this, but lifting this arbitrary constraint on HTMX feels like a consistent approach.

@Telroshan
Copy link
Collaborator

Hey, while I understand the concern, imho this doesn't and shouldn't belong to htmx ; htmx's goal is to make interactions with the server, and with a pure client-side interaction like this, it would require a lot of specific if statements in the codebase to skip many parts of the usual process (no XMLHTTPRequest to make, but still fire the settling phase and events after that with the swap logic...)

You may want to look into hyperscript as this one is a pure client-side library.

Note that I would strongly advise using custom JS here, with a simple element.remove() call.
Or, if you really want some reusable thing within htmx only, make an extension of your own that sets up elements with a [hx-swap="delete"]|hx-target] selector for example, or something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants