Maxim Gershkovich
Maxim Gershkovich

Reputation: 47149

Preventing jQuery timepicker addon from automatically opening

Does anyone know of a method to prevent the jQuery timepicker addon from automatically opening up when the textbox is focused? The documentation doesn't seem to provide a way and I'm currently looking at the source seeing if I can add the functionality but have I overlooked a simple way to accomplish this?

Upvotes: 1

Views: 2464

Answers (3)

sparkplug
sparkplug

Reputation: 1366

As the timepicker is an addon to the jquery ui datepicker, you can use the showOn option to specify that a button is used to trigger it. See the datepicker example here.

Here's an example of how this can be used for the time picker:

 $('input:text.timepicker').timepicker({
        showOn: "button",
        buttonImage: "/content/images/time_icon.png",
        buttonImageOnly: true
    });

Upvotes: 0

William Niu
William Niu

Reputation: 15853

How about just initiate the datetimepicker upon the button clicked (as well as focus the input box), and destroy the object when the picker is closed?

$('#button').click(function() {
    $('#timepicker').datetimepicker({
        onClose: function(dateText, inst) {
           $(this).datetimepicker('destroy');
        }
    }).focus();
});

Example: http://jsfiddle.net/william/NRH9r/

Upvotes: 2

dean oliver
dean oliver

Reputation: 945

try to use a jquery function called unbind() to remove the onfocus event from the datetimepicker. You can then call an instance of the datetime picker when you fire a click event, or any other event you wish to fire. Another option would be to call the onfocus event that fires the datetimepicker, And pass in an event object into the callback function. Then call for example event.preventDefault(). This will prevent the onfocus() event from doing what it normally does.

Upvotes: 0

Related Questions