Undo an action in Ember TextView using the escape key

How can I get Ember to start the controller action when the user presses the start key in the input field?

Given the following application code:

App = Ember.Application.create(); App.IndexRoute = Ember.Route.extend({ model: function () { return {foo: "bar"}; } }); App.IndexController = Ember.ObjectController.extend({ actions: { done: function () { console.log("done"); }, cancel: function () { console.log("cancel"); } } }); 

And the following HTML:

 <body> <script type="text/x-handlebars" data-template-name="application"> {{outlet}} </script> <script type="text/x-handlebars" data-template-name="index"> {{input value=foo action="done" cancel="cancel"}} </script> </body> 

I expect the cancel action in the controller to be triggered, but I get an error: Property 'cancel' of object [object Object] is not a function .

Here's a JSBin with the code above to illustrate. How can I do this job?

+6
source share
1 answer

It is not very documented, but sees the code ... https://github.com/emberjs/ember.js/blob/v1.1.2/packages/ember-handlebars/lib/controls/text_support.js#L106-L117

You must define your handlebars such as

 {{input value=foo enter='done' escape-press='cancel'}} 

JsBin http://jsbin.com/ObucELO/1/edit

+11
source

Source: https://habr.com/ru/post/957895/


All Articles