htmx icon indicating copy to clipboard operation
htmx copied to clipboard

Bootstrap dropdown is not working after navigate

Open mprince2k18 opened this issue 1 year ago • 4 comments

Its fun to work with HTMX and I really want to use HTMX for my Codecanyon project.

Teleman

but I am facing an issue.

I used hx-boost and hx-push-url in my anchor. The navigation working fine in my project but when I want to click on dropdown its not showing. I need to reload the page then it works.

Here is the screenshot of my page.

image

Another example:

https://github.com/bigskysoftware/htmx/assets/43857625/d12ef85a-efbf-4b2c-bb43-df6fda553b12

let me know if I missed something.

mprince2k18 avatar Nov 15 '23 05:11 mprince2k18

I've also encounterd this issue before. It seems all extra javascript is not loaded into the DOM when you use hx-boost and hx-push-url.

I encountered an issue where htmx's default AJAX behavior was interfering with our JavaScript functionality on a specific link that generates bulk PDFs. To temporarily address this problem, I set hx-boost="false" for that link, allowing it to perform a full page reload instead of an AJAX request. This ensured that our JavaScript worked correctly, and it served as a quick and practical solution to move forward with the project. However, it's worth noting that we're temporarily bypassing some of htmx's advantages for this specific use case, and we may need to explore a more comprehensive solution in the future to maintain the benefits of partial page updates while addressing the JavaScript issue. Have you in anyway encounter such problem before? If so how did you address the problem without causing a full page reload?

Problem:

<body hx-boost="true">
              <a href="{% url 'academics:generate_bulk_pdf' %}"
                   class="btn btn-sm bg-blue-black border-0"
                   style="text-transform: none;"
                > Generate Bulk PDF
                </a>
</body>

Temporal solution:

<a href="{% url 'academics:generate_bulk_pdf' %}"
                   class="btn btn-sm bg-blue-black border-0"
                   hx-boost="false"
                   style="text-transform: none;"
                > Generate Bulk PDF
 </a>

AmoahDevLabs avatar Nov 23 '23 04:11 AmoahDevLabs

Have you tried adding the HTMX head-support extension? The problem is probably that the extra JavaScript is in the <head> tag, which is normally not swapped in by HTMX.

svenberkvens avatar Nov 28 '23 21:11 svenberkvens

I just encountered this problem myself today. The issue for me was that the bootstrap JavaScript wasn't in the head. It was in the body, which meant it got duplicated every time the page was swapped. Moving the script tag to the head with a defer attribute fixed the issue with the dropdowns.

kvinck avatar Dec 07 '23 16:12 kvinck

I just encountered this problem myself today. The issue for me was that the bootstrap JavaScript wasn't in the head. It was in the body, which meant it got duplicated every time the page was swapped. Moving the script tag to the head with a defer attribute fixed the issue with the dropdowns.

Nice! I have been having a headache trying to solve this problem all day today. Just came across your solution and it worked!!! Thanks a lot!

jefffdelima avatar Jan 25 '24 11:01 jefffdelima