Skip to content

Instantly share code, notes, and snippets.

@kevinkucharczyk
Created August 22, 2018 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinkucharczyk/7fe442e025e3f81429c1ec0df48c4af4 to your computer and use it in GitHub Desktop.
Save kevinkucharczyk/7fe442e025e3f81429c1ec0df48c4af4 to your computer and use it in GitHub Desktop.
Item list form
import Ember from 'ember';
export default Ember.Controller.extend({
items: [],
itemToAdd: null,
submittedItems: null,
actions: {
add() {
this.get('items').push(this.get('itemToAdd'));
this.set('itemToAdd', null);
},
save() {
this.set('submittedItems', this.get('items'));
this.set('items', []);
this.set('isSubmitted', true);
},
cancel() {
this.set('items', []);
}
}
});
<form {{action "save" on="submit"}}>
<ul>
{{#each items as |item|}}
<li>{{item}}</li>
{{/each}}
</ul>
<div>
{{input value=itemToAdd}}
<button onclick={{action "add"}}>Add</button>
</div>
<button type="submit">Save</button>
<button onclick={{action "cancel"}}>Cancel</button>
</form>
{{#if isSubmitted}}
<h1>Success!</h1>
<p>Your items are:</p>
<ul>
{{#each submittedItems as |item|}}
<li>{{item}}</li>
{{/each}}
</ul>
{{/if}}
{
"version": "0.15.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment