Created
April 11, 2013 14:31
-
-
Save Bouke/5363838 to your computer and use it in GitHub Desktop.
Ember.Select allowing options to be disabled. Usage `{{view Ember.Select ... optionDisabledPath="content.disabled"}}`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var get = Ember.get, getPath = Ember.getPath, set = Ember.set, fmt = Ember.String.fmt; | |
Ember.Select.reopen({ | |
optionDisabledPath: null | |
}); | |
Ember.SelectOption.reopen({ | |
attributeBindings: ['disabled'], | |
init: function() { | |
this.disabledPathDidChange(); | |
this._super(); | |
}, | |
disabledPathDidChange: Ember.observer(function() { | |
var valuePath = get(this, 'parentView.optionDisabledPath'); | |
if (!valuePath) { return; } | |
Ember.defineProperty(this, 'disabled', Ember.computed(function() { | |
return get(this, valuePath); | |
}).property(valuePath)); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment