jeudi 11 février 2016

Send Action from component to route

I'm trying to send an action from my component (accordion-list) to the route (similation). In my component, we have a form with a input and a button, this component is inside a simulation Template :

templates/simulation.hbs 

{{accordion-list simu=model action="save"}}

and in my component ..

templates/components/accordion-list.hbs

<form class="form-horizontal" {{action "save" on="submit"}}>
  {{input value=model.name type="text"}}

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

In app/components/accordion-list.js I have to define an action for sending it to the route :

import Ember from 'ember';

export default Ember.Component.extend({

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

And here my route, also I have created the same action for saving the name of my simulation :

routes/simulation.js

import Ember from 'ember';

export default Ember.Route.extend({

    actions: {
        save: function() {
            //Create New Simulation
            var newSimu = this.store.createRecord('simu', {
                name: this.get('model.name')
            });
            newSimu.save();
        }
    }
});

When I click my button, the App send me an arror message like this :

Uncaught TypeError: adapter[operation] is not a function

I use my adapter adapter for saving my form in localstorage :

adapters/simulations.js

import ApplicationAdapter from './application';

export default ApplicationAdapter.extend({
    createRecord: function() {
        this.localStorage.set('simu', []);
    }

});

What is wrong in my code, I have tried every possibility but it never works. I need a help.

Aucun commentaire:

Enregistrer un commentaire