question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

hx-post posting form inside a bootstrap modal

See original GitHub issue

Hi there, Thank you for providing such a great library.

I noticed when I try and use a form inside a bootstrap model, the hx-post doesn’t work?

<form hx-post="/hello">
   <button class="btn btn-primary" type="submit">hello</button>
   @Html.HtmxAntiforgeryScript()
</form>

It tries to post the original page rather than the modal dialog form. Is there some special scripting I need to do?

This is an example of something I’m trying to achieve https://blog.benoitblanchon.fr/django-htmx-modal-form/

Any exmaple or idea on how to fix this?

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
khalidabuhakmehcommented, Jun 8, 2023

@dotnetshadow 👋 Hi again. I updated the sample to use Bootstrap JavaScript to give you full access to all the Bootstrap intended behaviors.

The trick with HTMX is you can return <script></script> elements that will execute immediately. This allows you to pass the initialization script necessary for modals.

Since the HTML and Script pass through HTMX’s request/response pipeline, you get a processed modal. Give it a try. It’s pretty sweet.

I’m writing a blog post about it 😃

1reaction
khalidabuhakmehcommented, Jun 8, 2023

No worries. Glad you’re trying out the library and enjoying it. Cheers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to post data on submit in a Bootstrap modal?
1 Answer 1 ... Your Modal form is outside the form tag so, it is not part of the HTML form and hence...
Read more >
Modal
Use Bootstrap's JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
Read more >
Modal · Bootstrap v5.0
Use Bootstrap's JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
Read more >
Modal forms with Django+HTMX - Good Code Smell
We set hx-target to this so that every HTMX request originating from the dialog (typically a form POST) remains in the dialog.
Read more >
Server-powered modals with HTMX - .NET Tools Guide
Modals are a powerful way to get a user's attention when you're acknowledging their action. A modal typically contains the most important ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found