Gazzer
Gazzer

Reputation: 4646

Change the focus on jQueryUI Datepicker on close

I want jQueryUI to change the focus to another element after the picker is closed:

$( "#datepicker" ).datepicker({
    onClose: function(dateText, inst) { 
        $("#time").focus();              //doesn't work
    $("#time").addClass('debug');    //works
}
});

The above should work but unfortunately datepicker seems to have a command inst.input.focus(); (I think) called after the onClose callback which resets the focus to the original input element. I'm wondering if there is way round this with bind().

Upvotes: 0

Views: 7453

Answers (1)

ShankarSangoli
ShankarSangoli

Reputation: 69905

You can have some delay and execute it if the plugin is setting the focus after onClose callback.

$( "#datepicker" ).datepicker({
    onClose: function(dateText, inst) { 
      setTimeout(function(){
        $("#time").focus();
      }, 200);
    }
});

Upvotes: 8

Related Questions