Allow changing modal options after creation
Created by: RentecTravis
Prerequisites
-
I have searched for duplicate or closed feature requests -
I have read the contributing guidelines
Proposal
Given a dismissible modal (created with the options `{backdrop: true, keyboard: true}'), some way to change the options after creation, to disable closing the modal, would be welcome.
Right now, in Bootstrap 5 you can modify a modal object's _config
properties. But you shouldn't, because those properties are not meant to be consistently available across minor versions. They may technically be public in scope but are not part of the public API.
What would be ideal is a public-API method for updating configuration. Something like, modal.config(options: {})
. I like that because config()
fits with some of the other method names like show()
, hide()
, toggle()
. However a name like setOptions()
may be clearer.
In any case, usage would look like this:
const el = document.getElementById('modal')
const modal = bootstrap.Modal.getOrCreateInstance(el)
modal.show()
// ...
// now when you want to prevent closing the modal
modal.config{{
backdrop: 'static',
keyboard: false,
})
Motivation and context
In my case the need for this arose from our having a Bootstrap modal which contained a two-step form. At the end of the form, we needed users to say "yes, this worked", or "no, start over"
Selecting yes logs their response and closes the modal. Selecting "no" takes them back to the first step.
If the user can just click the backdrop, or hit Esc to close the modal, they get confused because they can't find the result in their records. If we disable closing the modal from the beginning, then they have no way to leave.