Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save brettburley/7fe062b56f18140fd4b3a701a9c6ebb0 to your computer and use it in GitHub Desktop.

Select an option

Save brettburley/7fe062b56f18140fd4b3a701a9c6ebb0 to your computer and use it in GitHub Desktop.
Add new on input
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
things: Ember.computed(function() {
return [
Ember.Object.create({ name: 'thing 1' }),
Ember.Object.create({ name: 'thing 2' })
];
}),
actions: {
addThing(event) {
const startingValue = event.target.value;
this.get('things').addObject(
Ember.Object.create({ name: startingValue })
);
Ember.run.scheduleOnce('afterRender', () => {
Ember.$(event.target).val(null);
Ember.$('.thing-input:last').focus();
});
}
}
});
{{#each things as |thing|}}
<div>{{input class="thing-input" value=thing.name}}</div>
{{/each}}
<div>
{{input placeholder="New thing"
input=(action (action 'addThing'))}}
</div>
{
"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