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

Registering DOM element event listeners

In vanilla JavaScript, an application script traverses the DOM, setting up event listeners along the way. A typical form might look like the following:

<form name='tweet'>
    <textarea name='content' required></textarea>
     <input type='submit' value='tweet'></form>

<script>
    var form = document.forms.tweet;
    form.onsubmit = function(event){
      event.preventDefault();
       alert(form.content.value); 
};
</script>

Ember.js provides an abstraction over this, which allows developers to easily subscribe to element-specific events using the {{action ...}} helper. Our chapter contains such a form, as shown in the following code:

<form class="form form-horizontal" role="form" {{action "saveContact" this on="submit"}}> ... <button ...

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