Search code examples
javascriptember.jsevent-handlingdom-eventsember-select

Ember select - Select event is getting called on page load well


Please look at this fiddle. http://jsbin.com/ofONeQ/99/edit

I am using EmberJs select control and have added a select event to the control. Problem is as the page loads for the first time, system fires the select event. What I want is to system to wait for user to change the value in the control and then only system should fire this event.


Solution

  • it is because you are using two different properties selectedName and selectedNames.At the beginning it was undefined on load set to 1. :) check now

    App.IndexController = Ember.ArrayController.extend({
      selectedName: '1',
      names: ['1','2'],
      // this observer must work when selection changes
      nameSelected: function() {
    
        alert('topics selection changed!');
      }.observes('selectedName')
    });
    

    http://jsbin.com/ofONeQ/100/edit