Skip to content

Instantly share code, notes, and snippets.

@jenweber
Last active September 25, 2019 16:06
Show Gist options
  • Save jenweber/8072c4dc733817e7c6cfacff90c6eb7b to your computer and use it in GitHub Desktop.
Save jenweber/8072c4dc733817e7c6cfacff90c6eb7b to your computer and use it in GitHub Desktop.
Simple Select
import Ember from 'ember';
export default Ember.Component.extend({
selectedOption: null,
actions: {
setSelection: function(selected) {
this.set('selectedOption', selected)
console.log(this.get('selectedOption'))
},
submit: function(){
// save or sendAction
console.log(this.get('selectedOption'))
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Simple Select Component in Ember</h1>
<br>
My simplification of a blog post by <a href="https://balinterdi.com/2015/08/29/how-to-do-a-select-dropdown-in-ember-20.html">Balint Erdi</a>
<br />
<br />
<br>
{{outlet}}
{{my-component}}
<br>
<br>
<select onchange={{action "setSelection" value="target.value"}}>
<option disabled selected> -- Cats or Dogs? -- </option>
<option value="cats">Cats</option>
<option value="dogs">Dogs</option>
</select>
<button {{action 'submit'}}>Submit</button>
{
"version": "0.10.6",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.9.0",
"ember-data": "2.9.0",
"ember-template-compiler": "2.9.0",
"ember-testing": "2.9.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment