N P
N P

Reputation: 2619

Get form values from route ember

I have a form in my ember application, this form has a route with an action on. I want to grab my email and password values and do something with them.

However, I can't grab the values using this.get('email'); which I thought would work. How do I get the values and use them in my action? At the moment it just sets them as empty.

Here is my template.

<div class='page-header'>
  <h1>Login</h1>
</div>
{{input
  type='text'
  class='form-control'
  value=email
  placeholder='email'
}}
{{input
  type='password'
  class='form-control'
  value=password
  placeholder='password'
}}
<button
  class='btn btn-default'
  {{action 'login'}}
>
  Login In
</button>

Here is my route and action.

export default Ember.Route.extend({
  firebaseApp: Ember.inject.service(),
  actions: {
    login() {
      const auth = this.get('firebaseApp').auth();
      let email = this.get('email') || '';
      let password = this.get('password') || '';
      auth.signInWithEmailAndPassword(email, password)
      .then(() => {
        console.log("signed in this works");
      })
      .catch(function (error) {
        console.log(error);
      });
    }
  }
});

Upvotes: 0

Views: 269

Answers (1)

Steve H.
Steve H.

Reputation: 6947

When you use this.get() in a Route, this is the Route. When you use an expression in a template like {{input value=password}}, the variable is in the controller.

From the Route, you need to access those variables this way: this.controller.get('password')

Hope this helps.

Upvotes: 2

Related Questions