1

i have a {{input}}-helper in my template and i want to fire a method in the controller for every change in the {{input}}-helper.

application.hbs

<div class="page" id="main">
    {{input type="text" id="note-title" value=noteTitle action="createNote"}}
</div>

application_controller.js

YeoApp.ApplicationController = Ember.ArrayController.extend({
    actions: {
        searchTextChanged: function() {
            // this method should be called whenever
            // the input value changes, but somehow it doesn't work

        }.observes("noteTitle"),
        anotherMethod: function() {
            this.set("noteTitle", "Test!");
            //even this doesn't fire the observer when called
        }
    }
});

Any suggestions? Thanks in advance. Don't be afraid to ask questions.

2 Answers 2

3

I think that using observes inside of the actions hash don't work. You need to extract the searchTextChanged outside of that object:

YeoApp.ApplicationController = Ember.ArrayController.extend({
  searchTextChanged: function() {
    // this method should be called whenever
    // the input value changes, but somehow it doesn't work
  }.observes("noteTitle"),
  actions: {        
    anotherMethod: function() {
      this.set("noteTitle", "Test!");
      //even this doesn't fire the observer when called
    }
  }
});
Sign up to request clarification or add additional context in comments.

Comments

2

Ember 2 has a nice solution:
{{input key-press="action"}}

See the docs

1 Comment

This is helpful, but not as helpful as some code / example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.