Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Currently my site includes a search bar in my index.ejs file that uses {{action createSearch}} to call my controller's "createSearch" function when a user presses enter or clicks my search button. This works perfectly! Now I am testing out new functionality and want to call my newSearch function directly from my index.ejs file without any user interaction. I've tried using jquery on load to simulate the key press / click but the controller but that doesn't seem to invoke the action event.

edit: functional index.js code included

         {{view Ember.TextField id="new-search" placeholder="enter a few keywords"
             valueBinding="newSearch" action="createSearch"}}         
        <div id="gobutton" {{action createSearch}}><div id="gobutton_inner">SEARCH</div></div>
share|improve this question
1  
how does your index.ejs look like, code is much appreciated – intuitivepixel Jul 12 at 20:38
follow up question, from where do you want to invoke programmatically your createSearch action? from inside another controller maybe? – intuitivepixel Jul 12 at 22:55

1 Answer

For system-level actions like this you are better off using events on the ApplicationRoute. Your controllers/views can send an event like createSearch that the route handles typically via the controller that knows how to do this.

App.ApplicationRoute = Em.Route.extend({
  events: {
    createSearch: function(query) {
      var controller = this.controllerFor('search');
      controller.doSearch(query);
    }
  }
});

From any controller's action handler you can trigger the event with,

this.send('createSearch', query);

Or from a view,

this.get('controller').send('createSearch', query);

You will need to wire your individual action handlers to do this event triggering.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.