O'Reilly logo

Mastering Ember.js by Mitchel Kelonye

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling event actions

In the previous chapter, we learned how user actions can easily be delegated to controllers and routes from templates. Let's have a recap with an example:

{{! posts/new template }}

<form {{action 'save' model on='submit'}}>
  {{input name='title' value=title}}
  {{textarea name='body' value=body}}
  <button type='submit'>Create</button>
  <button type='cancel' {{action 'cancel' this}}>Cancel</button>
</form>

In this example, we defined two actions that will be handled by the corresponding controller as:

App.PostsNewController = Ember.ObjectController.extend({
  actions: {
    save: function(post){
      post.save();
    },
    cancel: function(post){
      post.rollback();
    }
  }
});

We already learned that all action handlers are defined in the actions property ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required