Yeats
Yeats

Reputation: 2065

How to reach the event when a <select> option is picked in Meteor?

Can't believe I have to ask for this, but googling gave me nothing even though there are a couple of similar questions on here.

In the Meteor docs it says about the change event:

A checkbox or radio button changes state. For text fields, use blur or key events to respond to changes.

But what about a select box?

Here's mine:

<select name="item-list-in-select-box">
  <option value="empty"></option>
  {{#each items}}
    <option class="select-option-value" value="{{name}}">{{name}}</option>
  {{/each}}
</select>

How do I reach the event when someone chooses a value here? change doesn't work, neither does click.

Edit: As requested, the code I expected to work but didn't:

'change .select-option-value': function() {
  console.log("hey")
}

I've also tried change select, change select.select-option-value, change [type=select], etc. etc. What is the right way?

Upvotes: 0

Views: 327

Answers (1)

Brian Shamblen
Brian Shamblen

Reputation: 4703

Change the scope of your event handler to use the name of the select element:

'change select[name="item-list-in-select-box"]': function() {
    console.log("hey")
}

Upvotes: 3

Related Questions