Eric Wilson
Eric Wilson

Reputation: 59365

How to use ember select for static dropdown?

This has to be easy, but I'm failing.

I have this in a template:

<select {{action 'setType' this value="target.value"}}> <!-- I've tried various things for the value -->
  <option value="0">Choice 1</option>
  <option value="1">Choice 2</option>
</select>

I have this in a controller:

setType: function(mymodel, type) {
  mymodel.set('type', type);
  mymodel.save();
}

The action is firing, the model is available, but none of my guesses are sending the value of the select to the controller action.

I'm using Ember 1.13.7

Upvotes: 1

Views: 268

Answers (1)

Henry Vonfire
Henry Vonfire

Reputation: 1281

You need to link your action to the event onchange:

<select onchange={{action "setType" value="target.value"}}>

Also, take into account that you are naming value the parameter that the action will receive and you aren't sending the model in that action as a parameter.

Upvotes: 2

Related Questions