Skip to content

Instantly share code, notes, and snippets.

@ehibun
Created May 13, 2016 17:18
Show Gist options
  • Save ehibun/75db5cd5dcb9cf68a3f9402bdc793f60 to your computer and use it in GitHub Desktop.
Save ehibun/75db5cd5dcb9cf68a3f9402bdc793f60 to your computer and use it in GitHub Desktop.
Multi-add
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
addItem(item) {
if (item) {
this.get('field').pushObject(item);
this.set('newValue', '');
}
},
deleteItem(index) {
this.get('field').removeAt(index);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return [1, 2, 3];
}
});
{{multi-add field=model placeholder="Add..."}}
<br>
{{outlet}}
<br>
<br>
{{#each field as |item index|}}
<div>{{item}} <a {{action "deleteItem" index}}>x</a></div>
{{/each}}
{{input
type="text"
placeholder=placeholder
class="input"
value=newValue}}
<button {{action "addItem" newValue}}>+</button>
{{yield}}
{
"version": "0.8.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.5.1",
"ember-data": "2.5.2",
"ember-template-compiler": "2.5.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment