Skip to content

modal.hide & oob content #11

@dwasyl

Description

@dwasyl

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions