Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Ui Datepicker month/year dropdown is not working in popup in latest firefox

Somehow my jQuery UI Datepicker Month/Year Dropdown not working in any popup in latest firefox .

When I click on Month or Year Dropdown, the options list doesn't appears.

Here is my Popup & Datepicker Code:

$( "#dialog-form" ).dialog({
    modal: true
});

$("#datepicker").datepicker({
    changeMonth: true,
    changeYear: true
});

I prepared a demo on JSfiddle too:

http://jsfiddle.net/469zV/2/

like image 913
StormTrooper Avatar asked Apr 27 '15 05:04

StormTrooper


People also ask

How do I display only the year in datepicker?

I will suggest to add formate on datepicker as "YYYY" so it will only show years inside it.

How can change date format in jQuery ui datepicker?

inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });

How do I change the pop up position of the jQuery datepicker control?

To change the position of the jQuery UI Datepicker just modify . ui-datepicker in the css file. The size of the Datepicker can also be changed in this way, just adjust the font size.

How can add date picker in jQuery?

JavaScript Code: $( function() { var from = $( "#fromDate" ) . datepicker({ dateFormat: "yy-mm-dd", changeMonth: true }) . on( "change", function() { to. datepicker( "option", "minDate", getDate( this ) ); }), to = $( "#toDate" ).


2 Answers

This is because the modal enforces focus on itself. Here is a solution for this as mentioned here . Add the below script to your js file. That's it.

jsfiddle: http://jsfiddle.net/surjithctly/93eTU/16/

Ref: Twitter bootstrap multiple modal error

// Since confModal is essentially a nested modal it's enforceFocus method
// must be no-op'd or the following error results 
// "Uncaught RangeError: Maximum call stack size exceeded"
// But then when the nested modal is hidden we reset modal.enforceFocus
var enforceModalFocusFn = $.fn.modal.Constructor.prototype.enforceFocus;

$.fn.modal.Constructor.prototype.enforceFocus = function() {};

$confModal.on('hidden', function() {
    $.fn.modal.Constructor.prototype.enforceFocus = enforceModalFocusFn;
});

$confModal.modal({ backdrop : false });

For Bootstrap 4:

replace : $.fn.modal.Constructor.prototype.enforceFocus
By: $.fn.modal.Constructor.prototype._enforceFocus
like image 189
Vijay Avatar answered Oct 20 '22 09:10

Vijay


I had to use

$.fn.modal.Constructor.prototype.enforceFocus = function () {
$(document)
  .off('focusin.bs.modal') // guard against infinite focus loop
  .on('focusin.bs.modal', $.proxy(function (e) {
    if (this.$element[0] !== e.target && !this.$element.has(e.target).length) {
      this.$element.focus()
    }
  }, this))
}

in order to restrict focus inside model when we use Tab to focus elements (Got from GIT).

tried this>>

$("#dateOfBirth").datepicker({
    beforeShow: function(input, inst) {
        $(document).off('focusin.bs.modal');
    },
    onClose:function(){
        $(document).on('focusin.bs.modal');
    },
    changeYear: true,
    yearRange : '-150:+0'
});

Now I can select the year :)

like image 31
ShAkKiR Avatar answered Oct 20 '22 09:10

ShAkKiR