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

Reply To: 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 Reply To: I want to make it such that autocomplete can be activated using tab also

#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.