Last active
August 2, 2016 03:37
-
-
Save mrozema/4d0159b76eca610d7706 to your computer and use it in GitHub Desktop.
Ember 2.0 compatible select box
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
import Ember from "ember"; | |
export default Ember.Helper.helper(function([content, group, contentGroupKey]) { | |
return content.filterBy(contentGroupKey, group); | |
}); |
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
import Ember from "ember"; | |
export default Ember.Helper.helper(function([lhs, rhs]) { | |
return lhs === rhs; | |
}); |
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
import Ember from "ember"; | |
export default Ember.Helper.helper(function([value]) { | |
return !value; | |
}); |
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
import Ember from "ember"; | |
export default Ember.Helper.helper(function([object, path]) { | |
return Ember.get(object, path); | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
content: [], | |
prompt: null, | |
optionValuePath: 'value', | |
optionLabelPath: 'label', | |
init: function () { | |
this._super(...arguments); | |
if (!this.get('content')) { | |
this.set('content', []); | |
} | |
}, | |
actions: { | |
change: function () { | |
let selectedIndex = this.$('select')[0].selectedIndex; | |
let content = this.get('content'); | |
// decrement index by 1 if we have a prompt | |
let hasPrompt = !!this.get('prompt'); | |
let contentIndex = hasPrompt ? selectedIndex - 1 : selectedIndex; | |
let _selection = content[contentIndex]; | |
this.sendAction('willChangeAction', _selection); | |
if (this.get('optionValuePath')) { | |
this.set('selection', _selection[this.get('optionValuePath')]); | |
} else { | |
this.set('selection', _selection); | |
} | |
this.sendAction('didChangeAction', _selection); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice