Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

polymer focus() on <paper-input> or <core-input> element

Is there a way to focus core-input or paper-input element?

What I want to achieve is: set cursor to input element so user can start typing.

This way he will not be forced to click on element before writing.

like image 297
wormhit Avatar asked Jun 30 '14 18:06

wormhit


People also ask

How do you focus on input element?

To set focus to an HTML form element, the focus() method of JavaScript can be used. To do so, call this method on an object of the element that is to be focused, as shown in the example. Example 1: The focus() method is set to the input tag when user clicks on Focus button.

Does focus scroll to Element?

An element can be focused by either using the autofocus="true" attribute or calling the element. focus() method. In both cases, the browser will automatically scroll the element into the viewport.

What is focus () JavaScript?

JavaScript | Focus() JavaScript focus method is used to give focus to a html element. It sets the element as the active element in the current document. It can be applied to one html element at a single time in a current document. The element can either be a button or a text field or a window etc.

How do you focus an input box in HTML?

Input Text focus() MethodThe focus() method is used to give focus to a text field. Tip: Use the blur() method to remove focus from a text field.


1 Answers

core-input has now a .focus() method it's delegating to the internal 's focus()

From the core-input.html code:

focus: function() {
    this.$.input.focus();
  }

What means that in your own code you need to call it like following:

elem[0].focus()

In my own case, I am calling focus from a timeout. In this case a bind is necessary for core-input to make a right use of this:

$timeout(elem[0].focus.bind(elem[0]));
like image 77
amit Avatar answered Oct 13 '22 01:10

amit