-
-
Save SaladFork/149d151187cb18b5ce9e to your computer and use it in GitHub Desktop.
Ember.Select allowing options to be disabled. Usage `{{view Ember.Select ... optionDisabledPath="content.disabled"}}` (Update to match `optionValuePath` and `optionLabelPath` implementation in Ember.js)
This file contains 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, set = Ember.set, computed = Ember.computed, defineProperty = Ember.defineProperty, observer = Ember.observer; | |
Ember.Select.reopen({ | |
optionDisabledPath: null | |
}); | |
Ember.SelectOption.reopen({ | |
attributeBindings: ['disabled'], | |
init: function() { | |
this.disabledPathDidChange(); | |
this._super(); | |
}, | |
disabledPathDidChange: observer('parentView.optionDisabledPath', function() { | |
var disabledPath = get(this, 'parentView.optionDisabledPath'); | |
if (!disabledPath) { return; } | |
defineProperty(this, 'disabled', computed(function() { | |
return get(this, disabledPath); | |
}).property(disabledPath)); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@SaladFork, this should work if the value at
optionDisabledPath
changes correct? Example looks great, but trying to apply it to something I have isn't working.