Since browsers have integrated tabs, we all use the tab key to change tabs.
Why not have the same functionality in a K2 form?
This is a nice feature, to implement by using the following Javascript code :
function checkTabPress(e) {
"use strict";
e = e || event;
var activeElement;
if (e.keyCode == 9) {
// tabulation pressed
if($(".tab.selected").closest('li').nextAll(':has(.tab):first').html() == null)
{ // we are on the last tab, so we go back on the first one
console.log('first tab');
$('.tab:first').click();
}
else
{
// Select next tab
console.log('next tab');
$(".tab.selected").closest('li').nextAll(':has(.tab):first').find('.tab').click();
}
}
}
// We attach the checkTabPress function to the "keyup" event
var body = document.querySelector('body');body.addEventListener('keyup', checkTabPress);
Javascript à ajouter a notre formulaire
Once the Javascript has been added to your form, you just have to run the form and play with the tab key.
Enjoy 😎