I am trying to create a scrollable modal dialog with a form in the modal-body. It is a long form, vertically, so I would like to utilize the modal-footer section to house the submit button since it stays stationary when scrolling the form/body.
I am using a straight forward modal structure like this:
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-body">
... FORM CONTENT ...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Understood</button>
</div>
</div>
</div>
</div>
The problem comes in when I try to insert the <form> and </form> tags. If I put <form> before modal-body and I put </form> after modal-footer, it breaks the static nature of the footer as well as the scrollable nature of the body.
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-scrollable">
<div class="modal-content">
<form action=".....">
<div class="modal-body">
... FORM CONTENT ...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Understood</button>
</div>
</form>
</div>
</div>
</div>
I understand that I could keep the form itself contained within modal-body and use a standard button outside of the form in order to submit the form via javascript, but I would prefer to keep the button inside the form so the form submits when enter is pressed.
I've also tried moving the form tags around the .modal div, around the .modal-dialog div and around the .modal-content div and each time it breaks the modal in a different way.
I have reconstructed this issue here: https://codepen.io/JayblesG/pen/MWRjvOx
Has anyone had success in accomplishing something like this?
It seems to work fine if you use modal-content as the
<form>...https://codeply.com/p/qFI1p5Dh27
This way you can use the HTML form submit button.