1

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

0

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

this.$ is undefined this.get('element') is also undefined, when called from my actions callback function
I want a reference to the input so I can clear its value
To clear its value, simply clear the property that it's bound to.
Your action is defined on the controller. You need to define the action on the view to get this.$ or this.get('element'). Remember to specify target='view' within the action directive. However, if you just clear the property bound to the input element, you won't need to worry about this.
Yup, that's the problem. I'm not using Views at all, I have all my code in the Ember.Route, I'm not sure why views are necessary, sounds like boilerplate to me. I'll look into it, ty.
1

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

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

1 Comment

Thanks, that example is useful and a better way of handling my specific case

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.