Skip to content

Instantly share code, notes, and snippets.

@SaladFork
Forked from Bouke/ember-select.js
Last active August 29, 2015 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SaladFork/149d151187cb18b5ce9e to your computer and use it in GitHub Desktop.
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)
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));
})
});
@lxcodes
Copy link

lxcodes commented Nov 13, 2014

@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.

@lxcodes
Copy link

lxcodes commented Nov 13, 2014

@SaladFork, disregard. Just wasn't loading the module facepalm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment