jeudi 30 avril 2015

Getting a hash of all values inside form in Ember

I am submitting a form to create a new Review in Ember.js. The form is linked to an action on my reviews/new controller.

Here is my form:
templates/reviews/new.hbs

  <form {{action "createReview" on="submit"}}>
    {{input value=name}}
    {{input value=content}}

    <input type="submit" value="Post this review" class="button">
  </form>


And my controller:
controllers/reviews/new/js

import Ember from 'ember';

export default Ember.Controller.extend({
  actions: {
    createReview: function(params) {
      console.log(this.get('name'));
      console.log(this.get('content');
    }
  }
});

At the moment my trouble is accessing the form field values in an efficent way. Note that this.get('name') does print out the value of the name input field and the same for this.get('content').

But is there a nice way to get all the form field values in a hash? Something like: this.get('allAttributes') which would output:

{name: "John Doe", content: "Bla bla-bla bla blaaaaah"}




Aucun commentaire:

Enregistrer un commentaire