How can I use bootstrap's modal events? #551

Open
gabriele-ricci-kyklos opened this Issue Oct 14, 2016 · 2 comments

Projects

None yet

3 participants

@gabriele-ricci-kyklos

I tried this code

bootbox
    .alert('Message')
    .on('show.bs.modal', function (e) { alert('showing') })

but the event is ignored. How can I use events?

@gabriele-ricci-kyklos gabriele-ricci-kyklos changed the title from How can I use bootstrap modal events? to How can I use bootstrap's modal events? Oct 14, 2016
@tiesont
Collaborator
tiesont commented Oct 16, 2016 edited

show seems to happen earlier than hooking into the jQuery/Bootbox object can allow. You can, however, hook into the shown.bs.modal event.

bootbox
    .alert('Message')
    .on('shown.bs.modal', function (e) { alert('showing') })

There is also the .init function you can call, which should run just prior to the modal being shown: http://bootboxjs.com/documentation.html#bb-function-init

You would use it like so:

 bootbox
    .alert('Message')
    .init('function (e) { alert('showing') })

.init seems to only be called once, though, so if you happen to do something that reuses a dialog, you're probably better off hooking into shown.bs.modal.

@tiesont tiesont added the Bootstrap label Oct 18, 2016
@djmattyg007

Like this:

var modal = bootbox.alert({
    message: "My Message",
    show: false
});
modal.on("show.bs.modal", function(e) { console.log("show!"); });
modal.modal("show");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment