ember-addons / bootstrap-for-ember

Bootstrap for Ember.js
http://ember-addons.github.io/bootstrap-for-ember
Apache License 2.0
704 stars 103 forks source link

Modals: how to create modal using View class, and access controller properties #107

Closed shainegordon closed 10 years ago

shainegordon commented 10 years ago

Maybe I am doing this wrong, but I would like to programmatically create a modal, passing the View class instead of the template (I want to do some additional DOM manipulation in the didInsertElement function.

if you look at this jsBin - http://emberjs.jsbin.com/makuroma/6/edit?html,js,console,output - you will see the modal render, and the controller property 'username' is bound to the template, but the view's didInsertElement does not fire.

if I now modify the modal creation - http://emberjs.jsbin.com/makuroma/7/edit?html,js,console,output - and pass the View class instead of template name to Bootstrap.ModalManager.open, this time the didInsertElement function does fire, but the controller binding does not work.

How do we make it so that we can create with a View (ie, have access to didInsertElement) AND have our controller binding working?

xypaul commented 10 years ago

Not completely sure, but maybe this is breaking your code:

  manualButtons: [
    Ember.Object.create({title: 'Submit', clicked: "submitManual"}),
    Ember.Object.create({title: 'Cancel', dismiss: 'modal'})
  ]

As discussed in this issue: https://github.com/ember-addons/bootstrap-for-ember/issues/100

asaf commented 10 years ago

@shainegordon Why in the first example do you expect anything to happen with ModalView if it's totally not in use?

Your jsbin samples causes an error so I can't fix them, but in general it should work okay including bindings, I don't see in your 2nd example any usage of the username property in the template,

But something like that should work.

            body = Ember.View.extend(
                template: Ember.Handlebars.compile('''
                hello: {{controller.username}}
                ''')
            )

If it doesn't help then please re-open and provide a working jsbin so I can help further,

Thanks.

shainegordon commented 10 years ago

Ahh I see now. In my templates for these modals that you have to use 'controller.username' and not just 'username'. I have never needed to explicitly specify the "controller" prefix in my templates before.

asaf commented 10 years ago

@shainegordon This is the scenario where your controller is objectController, happy it helped, thanks.