Skip to content

Instantly share code, notes, and snippets.

@rondale-sc
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save rondale-sc/2f23f9c3f66ba0d21ebd to your computer and use it in GitHub Desktop.

Select an option

Save rondale-sc/2f23f9c3f66ba0d21ebd to your computer and use it in GitHub Desktop.
import Ember from 'ember';
const genericSelectOptPath = function([opt, path]) {
if (path) {
return opt.get(path);
} else {
return opt;
}
};
export { genericSelectOptPath };
export default Ember.HTMLBars.makeBoundHelper(genericSelectOptPath);
<select onchange={{action "updateValue"}} id={{selectId}}>
{{#each options as |opt|}}
<option value={{generic-select-opt-path opt optValuePath}} selected={{ default-selected value opt options }}>
{{generic-select-opt-path opt optLabelPath}}
</option>
{{/each}}
</select>
import Ember from "ember";
import { genericSelectOptPath } from 'frontend/helpers/generic-select-opt-path';
export default Ember.Component.extend({
didInsertElement: function() {
if (!this.get('value')) {
return this.set('value', genericSelectOptPath([this.get('options.firstObject'), this.get('optValuePath')]));
}
},
actions: {
updateValue: function(e) {
return this.set('value', Ember.$(e.target).val());
}
}
});
{{ generic-select options=stateOptions value=value id=selectId optLabelPath="firstObject" optValuePath="lastObject"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment