I’m trying to use Twitter Bootstrap with Mithril. Usually redrawing a dialog with Bootstrap wrapped with Mithril works, but redrawing in a handler for "show.bs.modal"
event hides the dialog leaving the backdrop. It doesn’t solve even with setTimeout
, which should provide a different execution context. Why and how can I fix it?
Here is a simple PoC.
Gist: https://gist.github.com/173210/8c84966696276f1bfa3e298edb53da2b
Rawgit (working demo): https://rawgit.com/173210/8c84966696276f1bfa3e298edb53da2b/raw/34b0ac625962ee830d63829107eeb0473c735375/poc.html
In short, this doesn’t work.
jquery.on("shown.bs.modal", () => setTimeout(m.redraw, 2000));
2
Answers
Solved:
m.render
overwritesclassName
, which was altered by$(element).modal("show")
, so you must prevent that. You have two options:className
after$(element).modal("show")
and reflect it to the model.className
inconfig
wheninitialized
is false.I choose 2. It looks like the following:
m.redraw
only works for components that have been mounted withm.mount
orm.route
.I made a few changes to your code:
https://jsbin.com/wegeyi/edit?js,output
m.render
tom.mount
, we can replacef
withm.redraw
.className
,type
, etc can be expressed in them()
selector argument