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

modal.hide & oob content #11

Open
dwasyl opened this issue May 27, 2023 · 1 comment
Open

modal.hide & oob content #11

dwasyl opened this issue May 27, 2023 · 1 comment

Comments

@dwasyl
Copy link

dwasyl commented May 27, 2023

This code is great and versions have helped with lots of modals, but I found one flaw/issue. The if statement below fails to trigger if there is any content in the response, however if you have non-modal content included (ie an oob swap used for toasts or something) causes it not to fire (since there is a response). Any ideas on how to detect if there is no core swap response (ignoring oob content or otherwise)?

  htmx.on("htmx:beforeSwap", (e) => {
    // Empty response targeting #dialog => hide the modal
    if (e.detail.target.id == "dialog" && !e.detail.xhr.response) {
      modal.hide()
      e.detail.shouldSwap = false
    }
  })
@bblanchon
Copy link
Owner

Hi @dwasyl,

I addressed this issue in the blog post; see "Compatibility with the modal form pattern" toward the end.
In short, the (inelegant) solution consists in disabling the primary swap with HX-Swap: none and closing the modal with an additional HX-Trigger event.

Best regards,
Benoit

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