Autofocus select2 Inputs When Clicked

Autofocus Select2 Inputs When Clicked Image

C’mon… make it easy on yourself. Especially if you’re using ❤️ 

See that? With this snippet you get that blinky cursor so you can start typing right away without having to click again in the input. MAGIC!

What it does…

Forces a select2 input field to autofocus when clicked.

Why it does it…

On some sites I use a lot of select2 autocomplete dropdown lists (especially if I’m using ❤️). But sometimes you click on or tab to those little buggers and the text input doesn’t focus. This tries to fix that.

How it does it…

This JS finds the select2 input and listens for clicks. When the dropdown opens, it triggers the input to focus.

Use the JSON file for easily importing into your CodeSnippetsPro plugin. Use the PHP file or just copy/paste the code sample into your functions.php if you’re not using CodeSnippetsPro.

Related Snips

Leave a Reply

Your email address will not be published. Required fields are marked *