themesberg / themesberg/flowbite
Modal doesn't work as expected when combined with HTMX
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 9.4k
- Forks
- 862
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
I am trying to dynamically change the content of the modal with HTMX, when I trigger the modal it shows only for a split second and then it closes, leaving me only with the backdrop.
The button from where I am triggering the model is
<li>
<a
hx-get="{{ route('suppliers.edit', $supplier->id) }}"
hx-swap="innerHTML"
hx-trigger="click"
hx-target="#static-modal-holder"
hx-on::after-swap="showModalWindow('static-modal')"
href="{{ route('suppliers.edit', ['id' => $supplier->id]) }}"
data-modal-target="static-modal"
data-modal-toggle="static-modal"
class="block py-2 px-4 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Edit</a>
</li>
`function showModalWindow(id) {
initFlowbite();
const modal = FlowbiteInstances.getInstance('Modal', id);
modal.show();
}`
It appears that after I try to open the model from the edit section, the model from Create opens up with the same content that I dynamically sent for Edit. Seems like the model is not initializing again but using the previous content.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the showModalWindow entry point and the link's hx-on::after-swap, data-modal-target, and data-modal-toggle attributes. Reproduce the edit flow with the dynamically swapped content and inspect how FlowbiteInstances retrieves the Modal instance after initFlowbite(). Done means the edit modal opens reliably, stays open, and displays the fetched content without leaving only the backdrop or reusing the create modal.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- html, javascript, tailwindcss
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100