JQuery UI Datepicker loses focus when selecting date with mouse

后端 未结 10 1560
情歌与酒
情歌与酒 2021-02-01 02:16

I am using JQuery ui with datepicker and when a user tabs on to a field, they appropriately get the calendar pop up.

  1. User tabs (via key onto field
  2. User s
10条回答
  •  遇见更好的自我
    2021-02-01 02:41

    Having it focus on the same box ultimately causes the date picker to pop back up and what we really want is for it to go to the next field. Here is teh devised solution:

    1. Requires the tabindex attribute to be set on your fields.
    2. This is casting from a string to int in javascript (the * 1).
    3. This actually moves the selected field to the next element, instead of the current focus

      $(function(){
        $(".date").datepicker({
            onSelect: function(){
                currenttab = $(this).attr("tabindex");
                nexttab = currenttab * 1 + 1;
                $(":input").each(function(){
                    if ($(this).attr("tabindex") == nexttab)
                       $(this).focus();
                });
        }
        });
      });
      

    Any suggestions to improve on this technique are appreciated.

提交回复
热议问题