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

Only enable swap for hx-target-error #2509

Open
thenewguy opened this issue Apr 25, 2024 · 0 comments
Open

Only enable swap for hx-target-error #2509

thenewguy opened this issue Apr 25, 2024 · 0 comments

Comments

@thenewguy
Copy link

I want a form like this:

<div id="form-errors"></div>
<form
	hx-patch="/endpoint"
	hx-swap="none"
        hx-target-error="#form-errors"
>
	<input type="text" name="name" value="">
	<button type="submit" class="btn btn-primary">Submit</button>
</form>

On submit, path-deps catches the patch to /endpoint and refreshes the related content. So a successful submission should use hx-swap="none". However, that prevents hx-target-error from making the error swap so the user can correct the validation mistake.

So I have to do manually hide the response like this or with templating:

<div id="form-errors"></div>
<div id="form-success" style="display:none"></div>
<form
	hx-patch="/endpoint"
	hx-target="#form-success"
        hx-target-error="#form-errors"
	handlebars-template="form-error-template"
>
	<input type="text" name="name" value="">
	<button type="submit" class="btn btn-primary">Submit</button>
</form>

I cannot find a way to only enable swap for hx-target-error. It would be helpful if there was a way to only enable swap for error responses - or something that achieves the same effect.

Thanks!

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

1 participant