prompts using window.confirm when hx-confirm is set9ms ‣
this.server.respondWith('GET', '/test', 'Clicked!')
confirm.returns(true)
var btn = make('<button hx-get="/test" hx-confirm="Sure?">Click Me!</button>')
btn.click()
confirm.calledOnce.should.equal(true)
this.server.respond()
btn.innerHTML.should.equal('Clicked!')
stops the request if confirm is cancelled1ms ‣
this.server.respondWith('GET', '/test', 'Clicked!')
confirm.returns(false)
var btn = make('<button hx-get="/test" hx-confirm="Sure?">Click Me!</button>')
btn.click()
confirm.calledOnce.should.equal(true)
this.server.respond()
btn.innerHTML.should.equal('Click Me!')
uses the value of hx-confirm as the prompt0ms ‣
this.server.respondWith('GET', '/test', 'Clicked!')
confirm.returns(false)
var btn = make('<button hx-get="/test" hx-confirm="Sure?">Click Me!</button>')
btn.click()
confirm.firstCall.args[0].should.equal('Sure?')
this.server.respond()
btn.innerHTML.should.equal('Click Me!')
should prompt when htmx:confirm handler calls issueRequest1ms ‣
try {
var btn = make('<button hx-get="/test" hx-confirm="Surely?">Click Me!</button>')
var handler = htmx.on('htmx:confirm', function(evt) {
evt.preventDefault()
evt.detail.issueRequest()
})
btn.click()
confirm.calledOnce.should.equal(true)
} finally {
htmx.off('htmx:confirm', handler)
}
should include the question in htmx:confirm event1ms ‣
var stub = sinon.stub()
try {
var btn = make('<button hx-get="/test" hx-confirm="Surely?">Click Me!</button>')
var handler = htmx.on('htmx:confirm', stub)
btn.click()
stub.calledOnce.should.equal(true)
stub.firstCall.args[0].detail.should.have.property('question', 'Surely?')
} finally {
htmx.off('htmx:confirm', handler)
}
should allow skipping built-in window.confirm when using issueRequest2ms ‣
this.server.respondWith('GET', '/test', 'Clicked!')
try {
var btn = make('<button hx-get="/test" hx-confirm="Sure?">Click Me!</button>')
var handler = htmx.on('htmx:confirm', function(evt) {
evt.detail.question.should.equal('Sure?')
evt.preventDefault()
evt.detail.issueRequest(true)
})
btn.click()
confirm.called.should.equal(false)
this.server.respond()
btn.innerHTML.should.equal('Clicked!')
} finally {
htmx.off('htmx:confirm', handler)
}
should allow htmx:confirm even when no hx-confirm is set2ms ‣
this.server.respondWith('GET', '/test', 'Clicked!')
try {
var btn = make('<button hx-get="/test">Click Me!</button>')
var handler = htmx.on('htmx:confirm', function(evt) {
evt.detail.should.have.property('question', null)
evt.preventDefault()
evt.detail.issueRequest()
})
btn.click()
confirm.called.should.equal(false)
this.server.respond()
btn.innerHTML.should.equal('Clicked!')
} finally {
htmx.off('htmx:confirm', handler)
}