Ilia Choly
Ilia Choly

Reputation: 18557

Ember.TextField valueBinding to parentView

I'm trying to bind a Ember.TextField's value to a property in it's parent view. This code worked prior to upgrading to the latest version of ember. I've read about the new view scoping but can't figure out if/how that applies here.

Template my-template:

    Input: {{view Ember.TextField valueBinding="theValue" }}

View:

App.MyView = Em.View.extend({
    templateName: 'my-template',
    theValue: null,
    init: function(){
        this._super();
        this.set('theValue','');
    },
    keyDown: function(e){
       if(e.keyCode === 13){
            alert(this.get('theValue'));
       }
    }
});​

jsFiddle: demo

I've tried "parentView.theValue" and "view.parentView.theValue"

I know I can give the TextField a viewName and bind to that from inside MyView but I want to know why the previous method stopped working.

Update:

Upvotes: 5

Views: 3309

Answers (2)

sly7_7
sly7_7

Reputation: 12011

To give you an answer of why the previous method stopped working. I think the ember's team changed the bound context in the templates. Now I think the current context is the controller attached to the enclosing view.

I derived the @ebryn fiddle:

http://jsfiddle.net/Sly7/tcvhB/

Upvotes: 4

ebryn
ebryn

Reputation: 4407

I've updated your jsFiddle to work: http://jsfiddle.net/U3thg/23/

I just changed your valueBinding to "view.theValue".

 {{view Ember.TextField valueBinding="view.theValue" }}

Upvotes: 8

Related Questions