Check if datepicker is open

前端 未结 6 533
遥遥无期
遥遥无期 2021-01-01 13:19

I have a field with a datepicker. I want know if it is open. I\'ve tried with:

$(\"#filter_date\").datepicker( \"widget\" ).is(\":visible\")
<
相关标签:
6条回答
  • 2021-01-01 13:28

    This might be a possible bug in the past. Now this solution

    $("#filter_date").datepicker( "widget" ).is(":visible")
    

    works perfectly

    0 讨论(0)
  • 2021-01-01 13:40

    Access the datepicker's style attribute and compare it with a style when datepicker is hidden (display: none):

    var datePickerStyle = $('.datepicker').attr('style');
    var noneStyle = 'display: none;';
    if(datePickerStyle.indexOf(noneStyle) != -1){
         console.log('shown');
    } else {
         console.log('not shown');
    }
    
    0 讨论(0)
  • 2021-01-01 13:47
       var isCalendarVisible;     
       $(".datepicker).datepicker().on("show", function () {
              isCalendarVisible = true;
        }).on("hide", function () {
              isCalendarVisible = false;
        });
    

    I have used this approach for toggling of date-picker on clicking of a button. isCalendarVisible getting updated on 'show' & 'hide' of datepicker accordingly. I check value of 'isCalendarVisible' to open or close it manually .

        function toggleCalendar() {
            if (isCalendarVisible) {
                $(".datepicker .add-on").datepicker("hide");
            } else {
                $(".datepicker .add-on").datepicker("show");
            }
        }
    
    0 讨论(0)
  • 2021-01-01 13:51

    Simply set:

    #ui-datepicker-div { display: none; }
    

    in your CSS file and your code:

    $("#filter_date").datepicker( "widget" ).is(":visible")
    

    will work correctly!

    0 讨论(0)
  • 2021-01-01 13:51

    Do it like this.

    $('.inputCalendar').datepicker({
        dateFormat: "yy-mm-dd",
        monthNames: [ "01","02","03","04","05","06","07","08","09","10","11","12" ],
        monthNamesShort: [ "1","2","3","4","5","6","7","8","9","10","11","12" ],
        dayNames: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
        dayNamesShort: ["(Sun)", "(Mon)", "(Tue)", "(Wed)", "(Thur)", "(Fri)", "(Sat)"],
        yearSuffix: ".",
        showMonthAfterYear: true,
        autoSize: true,
        minDate : dateMin(),
        maxDate : dateMax(),
        beforeShow : function(){ //show
            $('.date').addClass('active');          
        },
        onClose: function(){ //hide
            $('.date').removeClass('active');
        }
    });
    
    0 讨论(0)
  • 2021-01-01 13:53

    Off the top of my head, I could think of using the beforeShow and onClose events defined for the datepicker control to toggle a class (or a flag) somewhere, and checking the presence of which to determine whether the datepicker control is open or not.

    0 讨论(0)
提交回复
热议问题