-
Hi, I am currently debugging an issue with HTMX and Alpine.js and building a minimal example. I replaced HTMX with a fake local AJAX call but it seems that there is an init step or similar missing. <!doctype html>
<html>
<head>
<script
defer
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"
crossorigin="anonymous"
></script>
</head>
<body id="admin-body" class="">
<style>
.bg-red {
background-color: red;
}
.bg-blue {
background-color: blue;
}
</style>
<script>
function getElement() {
return `<div id="dialog" x-data="{ show: true }" x-show="show">
<div @click.outside="show = false">
<form id="test-form">
<div >
<div x-data="{ input: false }" >
<input id="test" name="draft_name" :class="{ 'bg-blue' : input, 'bg-red': !input }">
</div>
</div>
</form>
</div>
</div>`;
}
</script>
<button
type="button"
x-data="{ fakeAJAX() { element = getElement(); console.log(element); dialogContainer = document.getElementById('admin-dialog'); dialogContainer.innerHTML = element; } }"
@click="fakeAJAX()"
>
Input
</button>
<div id="admin-dialog"></div>
</body>
</html> After clicking he button the DOM is updated, but the dialog is hidden, probably because shwo is not set properly. Is there some different way of updating the innerHTML or do I have to call some Alpine method? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Nope, this is working exactly as expected. The issue here is that the same click event that triggers the html swap also ends up triggering the So it's show, then immediately set to false. Anything else would cause an error to show and the element would be visible. You can see this here: https://awesomealpine.com/play?share=jDIUvH3lN68- |
Beta Was this translation helpful? Give feedback.
Nope, this is working exactly as expected.
The issue here is that the same click event that triggers the html swap also ends up triggering the
click outside
handler.So it's show, then immediately set to false.
Anything else would cause an error to show and the element would be visible.
You can see this here: https://awesomealpine.com/play?share=jDIUvH3lN68-