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

I want to make it such that autocomplete can be activated using tab also

Home Forums Product Support Forums Ajax Search Pro for WordPress Support I want to make it such that autocomplete can be activated using tab also

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #53603
    efi_2BlDefi_2BlD
    Participant

    I want to make it such that autocomplete can be activated using tab also on top of using right arrow key, please guide me

    #53605
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    Sure! You will need a tiny bit of custom javascript code for that:

    document.addEventListener("DOMContentLoaded", () => {
    	document.querySelectorAll('input.orig').forEach(function(el){
    		el.addEventListener('keydown', function(e) {
    			console.log(e.key);
    			if ( e.key === 'Tab' ) {
    				e.preventDefault();
    				const ev = new Event("keyup");
    				ev.which = 39;
    				el.dispatchEvent(ev);
    			}
    		})
    	});
    });

    Try adding this code via the Code Snippets plugin.

    If you want to use the functions.php file in your theme/child theme directory, then use this variation:

    add_action(
    	'wp_footer',
    	function () {
    		?>
    		<script>
    			document.addEventListener("DOMContentLoaded", () => {
    				document.querySelectorAll('input.orig').forEach(function(el){
    					el.addEventListener('keydown', function(e) {
    						console.log(e.key);
    						if ( e.key === 'Tab' ) {
    							e.preventDefault();
    							const ev = new Event("keyup");
    							ev.which = 39;
    							el.dispatchEvent(ev);
    						}
    					})
    				});
    			});
    		</script>
    		<?php
    	}
    );

    For more details you can check the safe coding guidelines.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.