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

x-target response code modifiers #73

Closed
mattwigham opened this issue May 18, 2024 · 2 comments · Fixed by #78
Closed

x-target response code modifiers #73

mattwigham opened this issue May 18, 2024 · 2 comments · Fixed by #78

Comments

@mattwigham
Copy link

First off, love the plugin. Thanks so much for putting in the time.

Second, I’d love the ability to put modifiers on x-target based on the response code returned from the server, similar to htmx's response targets extension. Perhaps something like:

<form id="my-form" action="/update" method="patch" x-target="body" x-target.422="my-form">

Perhaps something like this could be accomplished with intercepting the ajax:merge event with some custom retargeting? Either way, the Alpine modifier syntax would be some wonderful ergonomics.

Thanks again.

@mattwigham mattwigham changed the title x-target modifiers x-target response code modifiers May 18, 2024
@imacrayon
Copy link
Owner

Interesting! I hadn’t come across that extension before.
It would be cool if we could hack this by intercepting ajax:merged, but unfortunately that event doesn’t allow the target to be changed.

I think I like where your idea is going. It might even be a better alternative to the current follow and nofollow modifiers, those modifiers have never really sat right with me, and maybe we could replace them with something like x-target.302="_top" which would reload the page if a form submission redirects.

@mattwigham
Copy link
Author

Perfect!

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

Successfully merging a pull request may close this issue.

2 participants