Open metametadata opened 1 year ago
I looked in morphdom-swap.js
tests and they seem to cover that swapping happens, but not morphing. So I've tried to write the test to prove that morphing really happens by asserting that input value is preserved:
// test/ext/morphdom-swap.js
it('morphdom', function () {
this.server.respondWith("GET", "/test", '<input type="text" id="a"></input>');
var el = make('<input type="text" id="a" hx-get="/test" hx-ext="morphdom-swap" hx-swap="morphdom" hx-trigger="click"></input>')
el.value = 'foo';
// Act
el.click();
this.server.respond();
// Assert
byId("a").outerHTML.should.equal('<input type="text" id="a" class="">');
byId("a").value.should.equal('foo');
});
It fails with AssertionError: expected '' to equal 'foo'
.
But the similar test for alpine-morph
extension passes:
// test/index.html
<script defer src="https://unpkg.com/alpinejs@3.12.3/dist/cdn.min.js"></script>
<script src="https://unpkg.com/@alpinejs/morph@3.12.3/dist/cdn.min.js"></script>
<script src="../src/ext/alpine-morph.js"></script>
// test/ext/morphdom-swap.js
it('alpine-morph', function () {
this.server.respondWith("GET", "/test", '<input type="text" id="a"></input>');
var el = make('<input type="text" id="a" hx-get="/test" hx-ext="alpine-morph" hx-swap="morph" hx-trigger="click"></input>')
el.value = 'foo';
// Act
el.click();
this.server.respond();
// Assert
byId("a").outerHTML.should.equal('<input type="text" id="a" class="">');
byId("a").value.should.equal('foo');
});
Could be a bug—if you can reproduce and want to PR a fix go for it.
I can get
alpine-morph
andidiomorph
extensions to work, but notmorphdom-swap
.Demo code, https://jsfiddle.net/ymq5sjbr/1:
Steps
1) Select some file in the input. 2) Press
Submit
.Expected
Selected file stays in the input.
Actual
Input is empty.