vendredi 12 février 2016

sendAction doesn't work

I'm trying to build a form in my component, and I would like to send Action from my component to my Route. In my form, I have 4 inputs and one button for saving :

template/author.hbs

{{author-profile author=model action="save"}}

template/component/author-profile.hbs

<form class="form-horizontal" {{action "save" on="submit"}}>
{{input type="text" value=author.firstname}}
{{input type="text" value=author.water}}

{{input type="text" value=author.birth.town}}
{{input type="date" value=author.birth.date}}

<button  type="submit" class="btn btn-default">Save</button>
</form>

Totally for this form I need 2 models => Author and Birth :

models/author.js

export default DS.Model.extend({
  firstname: DS.attr('string'),
  surname: DS.attr('string'),
  births: DS.hasMany('birth')
});

models/birth.js

export default DS.Model.extend({
    author: DS.belongsTo('author'),
    date: DS.attr('date'),
    town: DS.attr('string')
});

And for creating record in LocalStorage, I need to send Action from component to Route :

components/author-profile.js

  actions: {
    save: function() {
      this.sendAction('action');
    }
  }

And now when I receive Action, I should save but I receive this error :

Uncaught TypeError: Cannot read property 'get' of null

Here is my route :

routes/author.js

actions: {
    save: function() {
        //Create New author
        var newAuthor = this.store.createRecord('author', {
            firstname: this.get('author.firstname'),
            surname: this.get('author.surname'),
            town: this.get('author.birth.town'),
            date: this.get('author.birth.date')
        });
        newAuthor.save();
    }
}

Aucun commentaire:

Enregistrer un commentaire