Reputation:
How Can I focus to the new Element pressing the TAB
var objClass = obj.className;
$(obj).datepicker({
changeMonth:true,
changeYear:true,
onClose:function()
{
$("#ui-datepicker-div").css("visibility", "hidden");
focusToNextField();
}
Upvotes: 0
Views: 91
Reputation: 74738
I suppose you need to have a keydown
event:
$(obj).datepicker({
changeMonth: true,
changeYear: true,
onClose:function() {
$("#ui-datepicker-div").css("visibility", "hidden");
// focusToNextField();
}
}).on('keydown', function(e){
e.preventDefault();
if(e.which === 9){
$(this).next(':input').focus();
}
});
Upvotes: 0
Reputation: 1966
Use .attr("tabIndex", "-1")
$('#dateelement').datepicker({
changeMonth: true,
changeYear: true,
}).next('button.ui-datepicker-trigger')
.attr("tabIndex", "-1");
Observe the cursor moves to the next textbox on hittin TAB button
Upvotes: 2
Reputation: 8101
Use $(":focusable")
to get current element and add focus on next element
var objClass = obj.className;
$(obj).datepicker({
changeMonth: true,
changeYear: true,
onClose:function() {
$("#ui-datepicker-div").css("visibility", "hidden");
var focusables = $(":focusable");
var current = focusables.index(this),
next = focusables.eq(current+1).length ? focusables.eq(current+1) : focusables.eq(0);
next.focus();
}
});
Upvotes: 0