Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save geekygrappler/a1305a25fd4730518796a70a7c07c88f to your computer and use it in GitHub Desktop.
Save geekygrappler/a1305a25fd4730518796a70a7c07c88f to your computer and use it in GitHub Desktop.
stackoverflow question#43090234
import Ember from 'ember';
export default Ember.Component.extend({
isBlankSelected: Ember.computed.empty('selectedOption'),
actions: {
loadFilter(selectedOption) {
this.set('selectedOption', selectedOption);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return [
{id:1, description: "Item1"},
{id:2, description: "Item2"},
{id:3, description: "Item3"},
{id:4, description: "Item4"},
{id:5, description: "Item5"},
{id:6, description: "Item6"}
];
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<select name="newType" class="parts-select full-width-combo" onchange={{action "loadFilter" value="target.value" }}>
<option value="" selected={{isBlankSelected}} hidden >Select </option>
{{#each model as |item|}}
<option value="{{item.id}}" selected={{eq selectedOption item.id}}>{{item.description}}</option>
{{/each}}
</select>
<br><br>
Push button below to select item 4 dynamically!<br>
<button onclick={{action 'loadFilter' 4}}>Select Item with id 4</button>
<br><br>
Push button below to nullify selection!<br>
<button onclick={{action 'loadFilter' null}}>Nullify selection</button>
{{my-component model=model}}
{
"version": "0.12.1",
"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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-truth-helpers": "1.3.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment