This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Input Search Field Won’t Focus After Click Magnifying Glass – 2.0

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Input Search Field Won’t Focus After Click Magnifying Glass – 2.0 Reply To: Input Search Field Won’t Focus After Click Magnifying Glass – 2.0

#54886
Ernest MarcinkoErnest Marcinko
Keymaster

Yea, sure!

It seems like it has something to do with the dialog, perhaps something with the settings, but I’m not sure. It’s part of Elementor, so you probably don’t want to disable that. I can’t tell if it’s the core script or something hooking into it though, most likely hook somewhere, but that’s impossible to find.

What I found though is that this script should get around it, I just tested and it worked from the console:

add_action('wp_footer', function () {
	?>
	<script>
		const f = ( select = false ) => {
			let input = document.querySelector('.dialog-widget .asp_m input.orig');
			if ( input === null ) {
				return;
			}
			input.focus();
			if ( select ) {
				input.setSelectionRange(0, 9999);
			}

		}
		jQuery(document).on('elementor/popup/show', ()=>{
			setTimeout(()=>{f(true);}, 800);
			document.querySelectorAll(".asp_main_container").forEach((el) => {
				el.addEventListener("asp_search_end", () => {
					setTimeout(()=>{f();}, 500);
				});
			});
		});
	</script>
	<?php
}, 999999);