Skip to content

Instantly share code, notes, and snippets.

@timgthomas
Last active February 7, 2018 18:03
Show Gist options
  • Save timgthomas/4af998fc1eaf411db6bbd4af12f5f7fe to your computer and use it in GitHub Desktop.
Save timgthomas/4af998fc1eaf411db6bbd4af12f5f7fe to your computer and use it in GitHub Desktop.
Multi-Inputs
import Ember from 'ember';
export default Ember.Controller.extend({
items: Ember.computed('model.@each.{hostname,port}', function() {
return JSON.stringify(this.get('model'));
}),
actions: {
addItem() {
this.get('model').pushObject({});
},
removeItem(item) {
this.set('model', this.get('model').reject(x => x === item));
},
},
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return Ember.A([
{ hostname: 'foo', port: 80, },
{ hostname: 'bar', port: 443, },
]);
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.hostname {
}
.port {
width: 40px;
}
{{#x-repeater items=model as |item|}}
<p>
{{input value=item.hostname class='hostname'}}
{{input value=item.port class='port'}}
<button {{action 'removeItem' item}}>&times;</button>
</p>
{{/x-repeater}}
<button {{action 'addItem'}}>Add</button>
<p>{{items}}</p>
{{#each items as |item|}}
{{yield item}}
{{/each}}
{
"version": "0.13.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.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment