So I’ve recently found the disabled attribute in the Em.TextField, however I can’t seem to re-enable the TextField after I’ve extended it with the disabled property set to true.
var app = Em.Application.create();
app.randomObj = Em.Object.create({
temp: null
});
app.textField = Em.TextField.extend({
valueBinding: 'app.randomObj.temp',
disabled: true
});
How do I remove the disabled property with Ember?
There are some issues with your sample code, I’ll adress each one and hope I can clear some things up.
Naming Convention
First of all you should have a look at the Emberist post about naming conventions: Classes should be named UpperCase and instances lowerCase – exception for applications and namespaces. So in your provided JSFiddle in your comment it’s
App.controllerandApp.ATextField.Declaring App as global variable
You are creating an instance of an
Ember.Applicationand assigning it tovar app. Although you should be careful when using global variables, in this case you should define your application on the global namespace, so it should beApp = Ember.Application.create();respectivelywindow.App = Ember.Application.create();. By declaring the app as global variable, you can use the powerful Bindings feature in your templates and your JS code.Bindings
The bindings should be declared on instances and not on classes. By this I mean you wouldn’t define the
valueBindingof yourApp.TextFieldin your class definition but rather move this to the concrete instance, for example in the template.In your provided JSFiddle in your comment your binding to the controller does not work because you don’t use one: to create a binding to a specific controller/object/… you’ll have to declare the property name you want to bind to and append a
BindingString. So it would bedisabledBinding: 'App.controller.shouldDisable'.Example
I’ve refactored your code, see http://jsfiddle.net/pangratz666/pLpKV/:
Handlebars:
JavaScript: