1

How do I display/hide a date picker only on click on a custom button?

My objective is to disable the functionality of the date picker by hiding it when I click somewhere other than the date picker.

1

1 Answer 1

1

Consider to use showOn button option, it enable a button near the datepicker.

You can use show and hide datepicker methods in order to toggle the visibility.

In the demo I have blocked the opening/closing anywhere so it's totally handled.

Code:

jQuery.datepicker._checkExternalClick = function () {};

$("#datepicker").datepicker({
    constrainInput: true,
    showOn: 'none',
    onSelect: function () {
        $(this).data('datepicker').inline = true;
    },
    onClose: function () {
        $(this).data('datepicker').inline = false;
    }
});

$('#toggle').click(function () {
    if ($(this).hasClass('opened')) {
        $("#datepicker").datepicker('hide');
    } else {
        $("#datepicker").datepicker('show');
    }
    $(this).toggleClass('opened');
});

Demo: http://jsfiddle.net/IrvinDominin/8wLg92x1/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.