Reputation: 1234
How do I call an action that is inside a controller from a view that uses a handlebar helpers (not sure if the handlebar helper is relevant to getting the controller but I wanted to mention it anyway)?
VpcYeoman.EditRecordCategoryView = Ember.TextField.extend({
//This is where i call the action from any controller
click: function() { // might be a property or some other action
this.get('controller').send('controllerActionName');
}
});
Ember.Handlebars.helper('edit-recordCategory', VpcYeoman.EditRecordCategoryView);
What would I do inside of that view to tell a controller that I want it to activate one of its actions?
Edit 1:
I added this.get('controller').send('controllerActionName');
to click:function(){}
,
and I receive the error Uncaught TypeError: undefined is not a function
on that line of code.
If I add this.get('controller').send('controllerActionName');
to didInsertElement: function(), i dont get any error at all.
Edit 2:
The handlebar helper is located in a list that uses an object controller named recordType
. 'recordType' is where that action is that I'm looking to call from the handlebar help's click event. However
in record_types.hbs
{{#each itemController="recordType"}}
{{#unless isEditing}}
{{categoryName}}
{{/unless}}
{{#if isEditing}}
{{edit-recordCategory class="edit" value=category_name focus-out="acceptChanges" insert-newline="acceptChanges"}} //This is the handlebar helper
{{/if}}
{{/each}}
We can assume that the isEditing
property in the record is true
since the handlebar helper will not be visible if it is false
.
Actually the action in the controller of my project is meant to toggle that property isEditing
.
Upvotes: 0
Views: 170
Reputation: 14963
To call a controller action from its view you do this:
VpcYeoman.EditRecordCategoryView = Ember.TextField.extend({
//This is where i call the action from any controller
click: function() { // might be a property or some other action
this.get('controller').send('controllerActionName');
}
});
Upvotes: 1