Skip to content

Commit 4446601

Browse files
author
carson
committed
regression for hyperscript htmx:afterRequest form reset integration
1 parent 8637f63 commit 4446601

File tree

3 files changed

+5313
-3140
lines changed

3 files changed

+5313
-3140
lines changed

test/core/regressions.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ describe("Core htmx Regression Tests", function(){
2424
"<div id='message2' hx-swap-oob='true'>I came from a message2 oob swap I should be third but I am in the wrong spot</div>" +
2525
"I'm page2 content (non-swap) I should be first")
2626

27-
var h1 = make("<h1 hx-get='/index2a.php' hx-target='#page2' hx-trigger='click'>Kutty CLICK ME</h1>" +
27+
var h1 = make("" +
2828
"<div id='page2' ></div>" +
2929
"<div id='message'></div>" +
30-
"<div id='message2'></div>")
30+
"<div id='message2'></div>" +
31+
"<h1 hx-get='/index2a.php' hx-target='#page2' hx-trigger='click'>Kutty CLICK ME</h1>")
3132
h1.click();
3233
this.server.respond();
3334
htmx.find("#page2").innerHTML.should.equal("I'm page2 content (non-swap) I should be first")
@@ -127,4 +128,27 @@ describe("Core htmx Regression Tests", function(){
127128
div1.innerHTML.should.equal("triggered");
128129
})
129130

131+
it('a form can reset based on the htmx:afterRequest event', function() {
132+
this.server.respondWith("POST", "/test", "posted");
133+
//htmx.logAll();
134+
135+
var form = make('<div id="d1"></div><form _="on htmx:afterRequest reset() me" hx-post="/test" hx-target="#d1">' +
136+
' <input type="text" name="input" id="i1"/>' +
137+
' <input type="submit" id="s1"/>' +
138+
'</form>');
139+
htmx.trigger(form, "htmx:load"); // have to manually trigger the load event for non-AJAX dynamic content
140+
141+
var div1 = byId("d1");
142+
var input = byId("i1");
143+
input.value = "foo";
144+
var submit = byId("s1");
145+
146+
input.value.should.equal("foo");
147+
submit.click();
148+
this.server.respond();
149+
150+
div1.innerHTML.should.equal("posted");
151+
input.value.should.equal(""); // form should be reset
152+
})
153+
130154
})

0 commit comments

Comments
 (0)