Implementing jQuery DatePicker in Bootstrap modal

后端 未结 7 1236
别那么骄傲
别那么骄傲 2020-12-01 13:41

Created jsfiddle for my issue http://jsfiddle.net/sudiptabanerjee/93eTU/

In modal window issue is on Change Month and Change Year combos.

a) IE 11: everythin

相关标签:
7条回答
  • 2020-12-01 14:16

    Building off of Surjith's answer, I added a try/catch block to resolve a ReferenceError exception for confModal being undefined.

    Coffeescript:

    enforceModalFocusFn = $.fn.modal.Constructor::enforceFocus
    
    $.fn.modal.Constructor::enforceFocus = ->
    
    try
      $confModal.on "hidden", ->
        $.fn.modal.Constructor::enforceFocus = enforceModalFocusFn
        return
      $confModal.modal backdrop: false
    catch error
      if error.name != 'ReferenceError'
        throw error
    
    0 讨论(0)
  • 2020-12-01 14:17

    Another workaround for this issue is removing tabindex="-1" attribute on your div.modal element.Tested on bootstrap 4.

    0 讨论(0)
  • 2020-12-01 14:23

    add z-index to your datepicker class

    0 讨论(0)
  • 2020-12-01 14:31

    jQuery version of @crftr answer

    var enforceModalFocusFn = $.fn.modal.Constructor.prototype.enforceFocus;
    $.fn.modal.Constructor.prototype.enforceFocus = function() {};
    try{
        $confModal.on('hidden', function() {
            $.fn.modal.Constructor.prototype.enforceFocus = enforceModalFocusFn;
        });
        $confModal.modal({ backdrop : false });
    }
    catch (error) {
        if(error.name != 'ReferenceError')
            throw error;
    }
    
    0 讨论(0)
  • 2020-12-01 14:31

    MORE EASY... just need to comment this line into your boostrap.js that.enforceFocus().

    0 讨论(0)
  • 2020-12-01 14:31

    Found an easier way to fix this datepicker issue. Make sure the JS is below jquery, jqueryUI lib calls.

    $("body").delegate("#date1", "focusin", function () {
          $(this).datepicker(
            {
              dateFormat: "yy-mm-dd",
              changeMonth: true,
              changeYear: true
            }
          );
    

    });

    $( "#date1" ).datepicker();
    
    0 讨论(0)
提交回复
热议问题