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

Bug? hx-on:* not fired when using hx-trigger="load" #3106

Open
michal-laskowski opened this issue Jan 5, 2025 · 0 comments
Open

Bug? hx-on:* not fired when using hx-trigger="load" #3106

michal-laskowski opened this issue Jan 5, 2025 · 0 comments
Labels
bug Something isn't working help wanted We would be interested in a PR that resolves that issue

Comments

@michal-laskowski
Copy link

This will not work

  it('before-request - without delay', function() {
    var requests = 0
    window.foo = 0
    this.server.respondWith('GET', '/test', function(xhr) {
      requests++
      xhr.respond(200, {}, 'Requests: ' + requests)
    })
    var div = make('<div hx-trigger="load, click" hx-get="/test" hx-on:htmx:before-request="window.foo += 1">Requests: 0</div>')
    div.innerHTML.should.equal('Requests: 0')
    this.server.respond()
    div.innerHTML.should.equal('Requests: 1')
    div.click()
    this.server.respond()
    div.innerHTML.should.equal('Requests: 2')
    delete window.foo
    window.foo.should.equal(2)
  })

When usind delay:1 it will work.

  it('before-request - with delay', function(done) {
    var requests = 0
    window.foo = 0
    this.server.respondWith('GET', '/test', function(xhr) {
      requests++
      xhr.respond(200, {}, 'Requests: ' + requests)
    })
    var div = make('<div hx-trigger="load delay:1ms" hx-get="/test" hx-on:htmx:before-request="window.foo += 1">Requests: 0</div>')
    div.innerHTML.should.equal('Requests: 0')
    this.server.autoRespond = true
    this.server.autoRespondAfter = 5

    setTimeout(function() {
      window.foo.should.equal(1)
      delete window.foo
      div.innerHTML.should.equal('Requests: 1')
      done()
    }, 50)
  })
@Telroshan Telroshan added bug Something isn't working help wanted We would be interested in a PR that resolves that issue labels Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted We would be interested in a PR that resolves that issue
Projects
None yet
Development

No branches or pull requests

2 participants