Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Searchbar user focus trigger search
This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko 1 year, 8 months ago.
- AuthorPosts
- July 1, 2021 at 6:11 pm #33818
Hello,
I had a few emails back and forth with Ernest about what I can achieve with this plugin and I have since purchased a license.
I am trying to emulate the search bar seen at merchbar dot com.
The plugin is able to do what I need with a normal search via text.But I am trying to emulate the functionality where the user simply focuses the search bar without having to type text. It gives a preview of certain taxonomy / item.
Ernest mentioned setting up a javascript trigger to initialize a search when the user focuses the search box.
Would be great if you could help.I do have access to a public server which we can use, I just need to move my test environment there first.
Thanks!
Attachments:
You must be logged in to view attached files.July 2, 2021 at 8:53 am #33826Hi,
This custom code should help you triggering the search whenever the input is focused:
add_action('wp_footer', 'wp_footer_asp_custom_script', 9999); function wp_footer_asp_custom_script() { ?> <script> (function(){ document.querySelectorAll('input.orig').forEach(function(el){ el.addEventListener('focus', function(){ el.dispatchEvent(new Event('input')); }); }); }()) </script> <?php }
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.
This code will trigger the search initially, whenever the user clicks on the input field.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.