Search code examples
ember.jsember-cli

Ember: Get the value of textarea from route


I want to get the value of the textarea to use inside my route. I tried using the method below, but the alert shows 'undefined' for that value. How would I go about getting the value of the textarea from the route? I am running the latest version of ember-cli.

Template

{{textarea type="text" value='name'}}
<button {{action 'submit'}} >Send</button>

Route

actions: {
    submit: function() { alert(this.get('name'));
    }   }

Solution

  • You have to pass a variable through action submit, which is bound to textarea value. Usually such a variable is defined in controller (or in wrapper component).

    //template
    {{textarea type="text" value=name}}
    <button {{action 'submit' name}} >Send</button>
    
    //controller
    name: 'defaultName'
    
    //route
    actions: {
      submit: function(val) { 
        alert(val);
      }
    }
    

    Working jsbin here