How to send form action from a component to route


#1

in my application I am using a component to create a form and i need to save form data to db when i submit it. i wish to do the saving from a route. how can i do that


#2

You could write the form data directly like this:

and use saveAction="saveAuthor" to call saveAuthor on the route:

/templates/components/blog-author.hbs

{{blog-author-edit author=author isEditing=isEditing saveAction="saveAction" deleteAction="deleteAction"}}

/templates/authors.hbs

{{#blog-authors authors=model page=page perPage=perPage createAction="createAuthor"}}{{outlet}}{{/blog-authors}}

With closure actions you can improve this.


#3
{{!-- route backed template, i.e. not a component --}}
<form {{action 'actionName' on='submit'}}>
  {{input value=model.firstname}}
  {{input value=model.lastname}}
  <button type="submit">Save</button>
</form>