JQuery Datepicker - close input click

I am using jQuery Datepicker and I have a little problem.

If the date picker is open and you click on the input field again, nothing will happen. How can I change this ... the collector, which will be closed upon input, will click if it is already open?

Thanks in advance...

+6
source share
7 answers

Since it is bound to focus(by default), you can just bind your own .mousedown()handler and it will not interfere, like this:

$("#datepicker").datepicker();
$("#datepicker").mousedown(function() {
    $(this).datepicker("hide");    
});

. mousedown, , , .

+6

. , . .

toggle:

$('.datepicker').mousedown(function() {
   $('#ui-datepicker-div').toggle();
});
+17

...

, datepicker , , , , ( , ).

, ( mousedown):

$(this).blur();

, :

$("#datepicker").datepicker();
$("#datepicker").mousedown(function() {
    $(this).datepicker("hide");
    $(this).blur();
});
+2

( console.log - ):

// call addToggleListener function one time to init
addToggleListener( $('.myDatepickerInputs') );

// the function
function addToggleListener( elm )
{
    elm.off( 'mouseup' );

    elm.on( 'mouseup', function()
    {
        $(this).off( 'mouseup' );
        $(this).datepicker( "show" );

        console.log( "show" );

        $(this).on( 'mouseup', function()
        {
            $(this).off( 'mouseup' );
            $(this).datepicker( "hide" );
            addToggleListener( $(this) );

            console.log( "hide" );
        });
    });
}

datepickers "onClose":

onClose: function()
{
    addToggleListener( $(this) );
}

Google Chrome.

+1

( ), :

$("#datepicker").datepicker();    
$("#datepicker").mousedown(function() {
    var cond = $(this).data('datepicker').dpDiv.is(':visible');
    $(this).datepicker(cond ? 'hide' : 'show');
});
0

, , ( ), (touchstart mousedown) :

var touchEvent = ('ontouchstart' in window || navigator.msMaxTouchPoints) ? "touchstart" : "mousedown";
$(".datepicker").on(touchEvent, function(){
    $('#ui-datepicker-div').toggle();
})
0

I was looking for a solution to the same problem and, relying on the help I got here, I came across a simpler solution regarding switching the date picker. I know that a lot of time has passed since this question was created, but I will leave it here anyway, in case someone has a similar problem in the future.

$("#datepicker").datepicker();
$("#datepicker").mousedown(function() {
    $('.datepicker-dropdown').toggle();
});
0
source

All Articles