4

I have created a jQuery UI datepicker like this:

 $.datepicker.setDefaults({
            changeMonth: true,
            changeYear: true,
            defaultDate: null,
            dateFormat: dateTimeFormat,
            showOn: 'both',
            buttonImageOnly: true,
            buttonImage: urlPath + 'Content/styles/images/calendar.gif',
            buttonText: 'Calendar'
        });

    $('input.datetime', controlContext).datepicker({
        onSelect: function (dateText, inst) {
            $(inst, controlContext).val(dateText);
            var dateSelected = $(inst, controlContext).datepicker("getDate");
        },
        beforeShow: function (input, inst) {
            $('.hasDatepicker').blur();
        }
    });

It works in all the major browsers. It works fine on Ipad also only if it is not on jQuery dialog. On jQuery dialog also if I use the datepicker for just selecting some date it is working fine. Only the dropdown for selecting some month or date is not working at all. I can see the dropdown options and even can click on any of the options but it is not hiding the option list after selecting any of the options, it just stays there.

After lot of debugging I found out that the onchange event that is supposed to fire at the time of selecting any month or year is not firing.

To repeat again even selecting of month/year works fine on iPad, if the datepicker is not on jQuery dialog.

Not sure what's going wrong.

2
  • could you post more relevant code, e.g. dropdown, and onchange? can you put them in jsfiddle? Commented Sep 2, 2011 at 14:16
  • are you using the latest JQuery UI? Is the dialog modal? Commented Sep 2, 2011 at 15:22

5 Answers 5

4

It seems to be something related to the ui-datepicker-div being created outside of the popup. I was having the same issue while using twitter bootstrap modals. I was able to get around it by using the following:

$('#ui-datepicker-div').ready(function() {
  var popup = document.getElementById('**ID OF YOUR POPUP**');
  var datePicker = document.getElementById('ui-datepicker-div');
  popup.appendChild(datePicker);
});

Hope that helps!

7
  • Thanks, that resolve the problem. Now the datepicker is not correctly paced but at least it's working ! Commented Oct 25, 2013 at 17:30
  • Indeed, same here; this solved the main problem. Any clue on how to fix the placement offset induced by the solution?
    – mabian69
    Commented Oct 30, 2013 at 8:19
  • @mabian69 Can you get me a screen shot of what you are seeing and a code sample?
    – JadedCore
    Commented Oct 30, 2013 at 16:56
  • Here: jsfiddle.net/mabian/kLdQm Month and year drop downs don't work in Firefox. One solution is moving the datepicker div and make it become a popup child, but this is a cumbersome solution because I have a JQuery Mobile app that is in fact a single page application, and the date picker control can be used inside or outside the popup.
    – mabian69
    Commented Oct 31, 2013 at 8:05
  • Also, moving the datepicker inside the popup screws up the datepicker placement logic... thanks.
    – mabian69
    Commented Oct 31, 2013 at 8:07
3

There is a bug reported: http://bugs.jqueryui.com/ticket/8989 (it's marked as fixed but the discussion suggests it wasn't fixed properly).

I'm experiencing the issue on Bootstrap Modal with jQuery-UI date picker on Firefox/Mac.

1
  • I am having this issue as well. Commented Feb 13, 2015 at 14:29
2

I was experiencing this issue while working with a twitter-bootstrap modal; just like JadedCore, who answered above. I fairly certain his assumption that the datepicker being created outside of the popup (in my case, the modal) was the cause of the problem.

I've used this datepicker in several modals and wanted something to 'fix' all locations. I took JadedCore's answer and modified to be more universal for multiple modals; I also move the datepicker back to the body when a modal is closed. I foresee issues with this example if there are multiple modals being displayed simultaneously, so beware.

$(function() {
    $('.modal').on('show.bs.modal', function (e) {
        var datePicker = document.getElementById('ui-datepicker-div');
        if (datePicker) {
            e.delegateTarget.appendChild(datePicker);
        }
    });

    $('.modal').on('hide.bs.modal', function (e) {      
        var datePicker = document.getElementById('ui-datepicker-div');
        if (datePicker) {
            $("body").append(datePicker);
        }
    });
});
0
1

This is working fine for me: http://jsbin.com/onuhos

-1

For me the solution was simply to increase the z-index of the dataPicker owner element, in your case increase z-index of $('input.datetime', controlContext)

Not the answer you're looking for? Browse other questions tagged or ask your own question.