Skip to content

Instantly share code, notes, and snippets.

@nelstrom
Last active January 24, 2017 21:20
Show Gist options
  • Save nelstrom/579092c9273166e209ab05efaad3c453 to your computer and use it in GitHub Desktop.
Save nelstrom/579092c9273166e209ab05efaad3c453 to your computer and use it in GitHub Desktop.
Select demo
import Ember from 'ember';
export default Ember.Controller.extend({
vehicle: null,
vehicles: ['Tesla', 'Chrysler', 'Toyota'],
actions: {
selectVehicle(vehicle) {
this.set('vehicle', vehicle);
}
}
});
import Ember from 'ember';
export function eq(params) {
return params[0] === params[1];
}
export default Ember.Helper.helper(eq);
<select onchange={{action "selectVehicle" value="target.value"}}>
<option
disabled={{if vehicle true false}}
selected={{if vehicle true false}}>Choose one:</option>
{{#each vehicles as |vehicleChoice|}}
<option
selected={{eq vehicle vehicleChoice}}>{{vehicleChoice}}</option>
{{/each}}
</select>
<select onchange={{action "selectVehicle" value="target.value"}}>
{{#if vehicle}}
<option disabled >Choose one:</option>
{{else}}
<option selected disabled >Choose one:</option>
{{/if}}
{{#each vehicles as |vehicleChoice|}}
{{#if (eq vehicle vehicleChoice)}}
<option selected>{{vehicleChoice}}</option>
{{else}}
<option>{{vehicleChoice}}</option>
{{/if}}
{{/each}}
</select>
{{#if vehicle}}<p>Selected: {{vehicle}}</p>{{/if}}
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.11.0",
"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.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment