show.bs.modal
test case – V5.0.1 – ComparisonsIssue: Modal event.preventDefault() for show.bs.modal: disables modal with fade class from being displayed again in V4 & V5.
The JavaScript for Bootstrap V4 & V5 stops a modal from being displayed again, once displaying the modal has been prevented using event.preventDefault()
.
This JS Bin using Bootstrap V5.0.1 shows event.preventDefault()
not working as expected after a modal has been prevented from displaying.
This JS Bin also includes examples of other Bootstrap components (dropdown, collapse, popover, and offcanvas) working as expected:
show.bs.component
event.event.preventDefault()
and nothing is displayed.The action of the show buttons can be confirmed through the developer console. As the listeners are sent an event, the listener will log the button and the switch status. For the dropdown, collapse, popover, and offcanvas buttons, the console will log an action every time a button is clicked.
For the modal button, an action will be logged every time the button is clicked, so long as the modal is enabled. Once the switch is changed to disable modals, only one more event will be logged. After that, the modal listener will not be sent any more events.