Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Input Search Field Won't Focus After Click Magnifying Glass
- This topic has 10 replies, 2 voices, and was last updated 2 years, 5 months ago by
Ernest Marcinko.
-
AuthorPosts
-
April 20, 2022 at 2:17 am #37572
dandolino32
ParticipantHi,
This is the staging website that shows the issue. We are using the search funtionality from the top right header of the site. We would like the cursor to focus on the search input field when you click the magnifying glass.
I activated the “Focus the search input when the page is loaded? ” option under Search box layout. And I found a ticket where you or one of your reps recommend adding jQuery code:
$(".proinput input.orig").focus();
I’ve tried both of those fixes and still can’t get it to work.
Can you please help?
https://scbbstaging.wpengine.com/
Thanks in advance,
DanApril 20, 2022 at 4:08 pm #37589Ernest Marcinko
KeymasterHi,
Some custom code will be needed for this, as the input focus has to be triggered on that 3rd party magnifier click event. Luckily it should not be too difficult.
Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.
add_action('wp_footer', 'asp_footer_custom_script', 999999); function asp_footer_custom_script() { ?> <script> (function($){ $('header .fa-search').on('click', function(){ setTimeout(function(){ $('.dialog-widget-content .asp_m input.orig').get(0).focus(); }, 250); }); })(WPD.dom); </script> <?php }April 20, 2022 at 9:10 pm #37609dandolino32
ParticipantThank you Ernest. Appreciate this!!!!
It works on desktop, but not on mobile.
Is there a fix to that?THanks
DanApril 21, 2022 at 8:21 am #37611Ernest Marcinko
KeymasterAre you sure? It does seem to work on our ends. Can you try clearing the mobile browser cache to make sure it is updated?
April 28, 2022 at 2:12 am #37660dandolino32
ParticipantYou cannot access this content.
April 28, 2022 at 1:45 pm #37670Ernest Marcinko
KeymasterThank you Dan! I have actually tested on a mobile device, and it worked just fine for some reason. Right now I don’t have an iPhone at hand, maybe that has something to do with the issue. Samsung and Huawei Chrome browsers seem to work just fine. IOS Safari is notoriously problematic with user generated events, such as input focus.
Maybe try this variation instead:
add_action('wp_footer', 'asp_footer_custom_script', 999999); function asp_footer_custom_script() { ?> <script> (function($){ $('header .fa-search').on('click touchstart', function(){ setTimeout(function(){ let input = $('.dialog-widget-content .asp_m input.orig').get(0); input.focus(); input.setSelectionRange(0, 9999); }, 250); }); })(WPD.dom); </script> <?php }This should explicitly capture the input.
April 28, 2022 at 7:33 pm #37675dandolino32
ParticipantHi Ernest,
I really appreciate your effort. I updated it, cleared all caches, opened private/incognito windows, and still doesn’t work on iphone. So strange. Would you be willing to try something else or use the credentials to troubleshoot?
Thanks
DanApril 29, 2022 at 8:48 am #37676Ernest Marcinko
KeymasterHi Dan,
I highly doubt that I can do anything more, that is the only way to do this. I did a bit of research just to be sure, and this is a known thing for IOS Safari, and there is no way around it apparently. It even varies from device to device, page to page, it is a real pain in the ass for developers – but nothing new, Safari always has been a problem to deal with from developers perspective.
April 29, 2022 at 4:52 pm #37677dandolino32
ParticipantUnderstood. Thank you so much for all your support
December 28, 2023 at 2:34 am #46457dandolino32
ParticipantHi Ernest,
Hope you are doing well.
The issue that you fixed in this post in reply #37670 has recently stopped working. I tried in Chrome and Safari desktop computer.
Could you please update the code to work?
Let me know if you want WP Admin or FTP access.
https://beachboardwalk.com/
Thank you
DanDecember 28, 2023 at 9:56 am #46459Ernest Marcinko
KeymasterHi Dan,
I see an error in the console, maybe it is related, but instead of the current code, try this:
add_action('wp_footer', 'asp_footer_custom_script', 999999); function asp_footer_custom_script() { ?> <script> jQuery(function($){ $('header .fa-search').on('click touchstart', function(){ setTimeout(function(){ let input = $('.dialog-widget-content .asp_m input.orig').get(0); input.focus(); input.setSelectionRange(0, 9999); }, 250); }); }); </script> <?php } -
AuthorPosts
- The topic ‘Input Search Field Won't Focus After Click Magnifying Glass’ is closed to new replies.