Farzher
Farzher

Reputation: 14563

Ember.js input action get element

I'm sorry I couldn't figure out something so basic and had to ask here, but in the newUser callback function, how do I get a reference to that input element?

{{input action="newUser"}}

I tried param=this this.$() this.get('element') Nothing worked in Ember 1.7

Upvotes: 1

Views: 634

Answers (2)

user663031
user663031

Reputation:

You could try

this.$('input')

which will return a jQuery-style element set on which you can do more jQuery-type things, or

this.get('element').querySelector('input')

this.get('element') will return the view element, so you need to poke down into it to find the input element, whether by tagname as above, or via some other selection mechanism such as id or class.

However, this assumes the action is defined within the view, where this.$ and this.get('element') are defined. It will not work if the action is defined on the controller or route. It is a common Ember pattern to have an action handler on the view, which does view-related things, and then sends some action along to the controller for it to do controller-related things.

However, if you are trying to retrieve the input element just in order to muck with its value, then you can do this much more easily by simply modifying the property bound to the input elements' value.

Upvotes: 2

Oliver
Oliver

Reputation: 978

You don't even need a reference to the element to clear it. Just use data-binding:

http://emberjs.jsbin.com/telat/1/edit

Upvotes: 1

Related Questions