Re: Using Twitter Bootstrap modal dialogs with Knockout.js

5,933 views
Skip to first unread message

Brendan McLoughlin

unread,
Nov 17, 2012, 9:14:42 AM11/17/12
to knock...@googlegroups.com
Well done Andrew. I'll be sure to refer to this in the future when designing interactions between viewModels. I especially like the use of a deferred to create two separate paths for success and cancel actions.

I'd recommend calling ko.cleanNode on your modal before removing it from the dom inside of whenUIHiddenThenRemoveUI. This will help prevent memory leaks by releasing all of the viewModel's references to the node.

-Brendan

On Thu, Nov 15, 2012 at 11:15 AM, Andrew Davey <and...@equin.co.uk> wrote:
I've written a blog post that shows a nice way to use Twitter Bootstrap's modal dialog plugin in a Knockout-based application, without polluting your views models with DOM code.

The techniques covered include using ko.renderTemplate to dynamically generate UI, and using jQuery's deferred object to elegantly wait for the modal's return value.

You can read the post here:
http://aboutcode.net/2012/11/15/twitter-bootstrap-modals-and-knockoutjs.html

What do you think about the approach? Are there any improvements or enhancements you'd like to see?

Andrew Davey

unread,
Nov 18, 2012, 11:34:30 AM11/18/12
to knock...@googlegroups.com, btmclo...@gmail.com
Thanks Brendan, good catch on the need to call ko.cleanNode!

Casey Corcoran

unread,
Nov 19, 2012, 12:25:19 PM11/19/12
to knock...@googlegroups.com, btmclo...@gmail.com
I believe the best way to handle this kind of thing is with a custom binding...

Here's a quick example, let me know what you think:

dmoo...@googlemail.com

unread,
Feb 17, 2013, 5:43:58 PM2/17/13
to knock...@googlegroups.com, btmclo...@gmail.com
In this fiddle, if you don't exit via one of the two buttons - ie clicking on the black background, it then seems to lock up. Nice example though. 
I'll let you know if I figure it out :-)

dmoo...@googlemail.com

unread,
Feb 17, 2013, 6:07:36 PM2/17/13
to knock...@googlegroups.com, btmclo...@gmail.com, dmoo...@googlemail.com
Forked very minor revision to fix above issue - http://jsfiddle.net/hcL4s/

Now - 

<!-- Create a modal via custom binding -->
<div data-bind="bootstrapModal:modal" data-keyboard="false" data-backdrop="static"></div>
Reply all
Reply to author
Forward
0 new messages