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

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

Viewing 4 posts - 16 through 19 (of 19 total)
  • Author
    Posts
  • #54909
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Okay, I suspected it has nothing to do with Elementor either, it wouldn’t make much sense, unless it was a bug of some sort, which at this point can be crossed out.

    You can try this variation, but at this point I have no idea if it’s going to change anything at all:

    add_action('wp_footer', function () {
    	?>
    	<script>
    		let fakeInput;
    		const detectIOS = () => {
    			if (
    				typeof window.navigator != "undefined" &&
    				typeof window.navigator.userAgent != "undefined"
    			)
    				return window.navigator.userAgent.match(/(iPod|iPhone|iPad)/) != null;
    			return false;
    		};
    		const focusInput = ( targetInput ) => {
    			if ( !detectIOS() ) {
    				targetInput?.focus();
    				return;
    			}
    
    			if ( targetInput === undefined || fakeInput === undefined) {
    				// create invisible dummy input to receive the focus first
    				fakeInput = document.createElement('input')
    				fakeInput.setAttribute('type', 'text');
    				fakeInput.style.position = 'absolute';
    				fakeInput.style.opacity = "0";
    				fakeInput.style.height = "0";
    				fakeInput.style.fontSize = '16px'; // disable auto zoom
    				// you may need to append to another element depending on the browser's auto
    				// zoom/scroll behavior
    				document.body.prepend(fakeInput);
    			}
    
    			if ( targetInput === undefined ) {
    				// focus so that subsequent async focus will work
    				fakeInput.focus();
    			} else {
    				targetInput.focus();
    			}
    		}
    		const f = ( ) => {
    			let input = document.querySelector('.dialog-widget .asp_m input.orig');
    			if ( input === null ) {
    				return;
    			}
    			focusInput(input);
    		}
    		jQuery(document).on('elementor/popup/show', ()=>{
    			setTimeout(()=>{f(true);}, 800);
    			document.querySelectorAll(".asp_main_container").forEach((el) => {
    				el.addEventListener("asp_search_end", () => {
    					focusInput();
    					setTimeout(()=>{f();}, 1000);
    				});
    			});
    		});
    	</script>
    	<?php
    }, 999999);
    #54948
    dandolino32dandolino32
    Participant

    Hi Ernest,
    I found out the culprit, what’s unfocusing input every time you type. On the elementor popup settings, there was an animation delay. Removed it and now it works great again. Just wanted to let you know in case someone else has a similar issue. Thanks again for your support.

    #54952
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Nice find, thank you very much for sharing! I will keep this in mind.

    I suspect it inherently applies to all animations, therefore it triggers every time you type, removing the focus, explains everything.

    #54958
    dandolino32dandolino32
    Participant

    Yes. Thanks again.

Viewing 4 posts - 16 through 19 (of 19 total)
  • You must be logged in to reply to this topic.