emberjs-addons/ember-bootstrap

Can't set templateName of custom bodyViewClass of ModalPane

Opened this issue · 5 comments

I'm trying to create a custom bodyViewClass to replace the default modal body class which is too simple for my needs. Whenever I try to set a templateName, however, I get the following error:

Uncaught Error: assertion failed: You specified the templateName vehicle/price/net-reduction for <(subclass of Ember.View):ember1414>, but it did not exist.

I can use the same templateName elsewhere in the app and it displays just fine. This only comes up in the ModalPane instance. Below is the code for the ModalPane:

Bootstrap.ModalPane.popup({
  heading: 'Net Reduction',
  message: 'test',
  bodyViewClass: Ember.View.extend({
    templateName: 'vehicle/price/net-reduction'
  }),
  primary: 'Submit',
  secondary: 'Cancel',
  showBackdrop: true,
  callback: function(opts, event) {

  }
});

This is actually an issue with the removal of the default container in Ember-Core. Sadly the error coming up is a bit obtuse.

Explanation is here https://gist.github.com/stefanpenner/5627411.

There are a couple of ways of fixing it, you can pass the default container into the popup function if you have access to it from where you are calling popup.

I personally have overriden the popup method, but I have worries that it wouldn't work universally so I never contributed it back to ember-bootstrap.

Bootstrap.ModalPane.reopenClass({
  popup: function(options) {
    var modalPane, rootElement;
    if (!options) options = {};
    modalPane = this.create(options);

    if (!modalPane.container && modalPane.get("controller")) {
      modalPane.container = modalPane.get("controller").container;
    }

    rootElement = get(this, 'rootElement');
    modalPane.appendTo(rootElement);
    return modalPane;
  }
});

This is definitely something that should be fixed in ember-bootstrap, I'll have a think about it.

Ah, interesting issue. It would have taken a while for me to figure that out on my own, thanks for the help!

Note: To use the fix you posted the ModalPane has to be passed a controller somehow. I ended up passing it in hash I gave to the popup method.

Any movement on this? Is ember-bootstrap going to incorporate a fix?

We should indeed.