Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • Tom Dale's Explanation
  • Ember Source
like image 327
Ilia Choly Avatar asked Jun 11 '12 19:06

Ilia Choly


2 Answers

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" }}
like image 55
ebryn Avatar answered Nov 03 '22 12:11

ebryn


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/

like image 33
sly7_7 Avatar answered Nov 03 '22 13:11

sly7_7