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)
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.
<paper-input> is a single-line text field with Material Design styling.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With