Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to focus a paper-input with Polymer 1.0?

This question is a follow-up to this one: polymer focus() on <paper-input> or <core-input> element

How can I focus in a paper-input element using the Javascript API ?

(using Polymer 1.0)

like image 981
vdegenne Avatar asked Jun 12 '15 14:06

vdegenne


People also ask

How do you make an input field focused?

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.

What is paper input?

<paper-input> is a single-line text field with Material Design styling.


1 Answers

If you have an element:

<paper-input id="my-input" label="What's on your mind?"></paper-input>

paper-input is a wrapper for business logic and stylish of a more deep-down input element which you can reach through:

document.getElementById('my-input').$.input

To focus, just write:

document.getElementById('my-input').$.input.focus();
like image 175
vdegenne Avatar answered Sep 28 '22 16:09

vdegenne