Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid reopen datepicker after select a date

Only in IE with this code

$('#datepicker').datepicker({
    onSelect : function(x, u){
     $(this).focus();   
    }
});

when I select a date, the datepicker reopen itself because I added $(this).focus(); in onSelect. How I can to resolve this issue? (Example)

I'm using jquery 1.8.2 and jquery-ui 1.9

like image 657
Webman Avatar asked Oct 22 '12 11:10

Webman


People also ask

How do I restrict date in date picker?

You can restrict the users from selecting a date within the particular range by specifying MinDate and MaxDate properties. The default value of MinDate property is 1/1/1920 and MaxDate property is 12/31/2120 . Dates that appears outside the minimum and maximum date range will be disabled (blackout).

How do I close DateTimePicker after selecting date?

$(document). mouseup(function (e) { $('#example1'). Close(); });

How can I hide datepicker after selecting date in jQuery?

Syntax: $(". selector"). datepicker("hide");

How would you restrict date picker selection based on the entry in another date field?

The requirement is also to be able to use dates in the format "dd-MMM-yy". For example, in the first date field, the user selects 26-Nov-16. Then, when they click on the date picker for the second date field, the earliest date they are able to select is 26 Nov.


1 Answers

I came across this issue today and had a different solution work for me. My scenario was that my DatePicker was inside a jQuery UI Dialog popup. Everything worked fine in Chrome, but in IE, the calendar would always reappear after selecting a date.

As it turns out, there is an open bug for this in jQuery 1.10.1: http://bugs.jqueryui.com/ticket/9125

There is also a JSFiddle linked to that demonstrates the bug in IE. There are two ways to get this to work in IE:

  1. Set modal to false
  2. Focus on another element right after date selection

I went with #2, and here is an example of the fix (just updating the JSFiddle code):

Markup:

<div id="dialog">
    <input id="datepicker" />
    <input type='button' value='save' id='btnSave'/>    
</div>

JS:

$( "#datepicker" ).datepicker({onSelect: function() { $('#btnSave').focus(); }});
$( "#dialog" ).dialog({ modal: true });

Hopefully this helps someone in the future!

like image 136
lhan Avatar answered Nov 15 '22 21:11

lhan