0

At the bottom of the durandal docs for dialogs / modals (http://durandaljs.com/documentation/Showing-Message-Boxes-And-Modals.html) there's some syntax for repositioning a dialog. The dialog I have gets gradually bigger as the user selects stuff, so every time a selection is made, I'd like to call reposition(). I tried following along with this:

vm.compositionComplete = function (child, parent, context) {

        var addEditDialog = dialog.getDialog(context.model); // resolves

        // whenever something is selected:
        addEditDialog.context.reposition(vm); // no method 'reposition'

}

But I get an error - there is no function reposition. What am I doing wrong?

SB2055
  • 12,272
  • 32
  • 97
  • 202

1 Answers1

0

You can set up a custom dialog context that responds to a reposition message (using Durandal's app.trigger()). You would trigger the message upon some event in your dialog (such as, as you say, the user's selecting stuff).

Also in that custom dialog context, create a method call reposition. In the activate or attached handler of that custom dialog context, subscribe to the message you use to trigger a reposition.

I'm advocating a messaging approach because you may wish to isolate your "selection viewModel" in its own viewModel, and then compose it into your custom dialog context. With this approach, your selection viewModel and your custom dialog context would be loosely bound. That way, you could use your selection viewModel elsewhere in your code (and even have some other viewModel, instead of the custom dialog context, respond to the reposition message).

  • Thanks for this. Do you know why the documented syntax is not working though? I'd rather not make significant changes here :/ – SB2055 Jun 19 '14 at 16:15
  • Take a look at this: https://github.com/BlueSpire/Durandal/pull/362. `reposition` is a 2.1 feature. You indicated that you're using 2.0. –  Jun 19 '14 at 16:33