Darion Badlydone
Darion Badlydone

Reputation: 947

jQuery Timepicker reset

Someone know how to reset the jQuery Timepicker http://trentrichardson.com/examples/timepicker/ ? I need to set the Hours and the Minutes to 0 before open it up.

I tried to do that but it doesn't work:

$('#timepicker').timepicker({
    hour:0, minute: 0});

I set the value of the bind textbox to empty but If I show the timepicker, it still have the previously value setted.

Thanks

Upvotes: 2

Views: 10144

Answers (5)

Kishan Chauhan
Kishan Chauhan

Reputation: 1236

Find this $.datepicker._updateDatepicker = function(inst) addon.js file and add this code to clear input.

  var buttonPane = $(this).datepicker("widget").find(".ui-datepicker-buttonpane");

  $("<button type='button' class='ui-datepicker-clean ui-state-default ui-priority-primary ui-corner-all'>Clear</button>").appendTo(buttonPane).click(function(ev) {
                    inst.input.val('');
    });

Upvotes: 0

Rodrigo Balest
Rodrigo Balest

Reputation: 336

Try setting defaultValue to "00:00".

It worked to me.

Upvotes: 0

tong.zhilian
tong.zhilian

Reputation: 1

Try this.

The solution is not good enough(Using some internal variables).

Works for me though.

[tong@localhost javascripts]$ cat jquery-ui-timepicker-clear-button.js
(function($){
    var old_fn = $.datepicker._updateDatepicker;

    $.datepicker._updateDatepicker = function(inst) {
        old_fn.call(this, inst);

        var buttonPane = $(this).datepicker("widget").find(".ui-datepicker-buttonpane");

        $("<button type='button' class='ui-datepicker-clean ui-state-default ui-priority-primary ui-corner-all'>Clear</button>").appendTo(buttonPane).click(function(ev) {
            inst.input.val('');
            $(inst.settings.altField).val('');
        });
    }
})(jQuery);

Upvotes: 0

feeela
feeela

Reputation: 29932

I think you need to set alwaysSetTime to false:

alwaysSetTime – Default: true - Always have a time set internally, even before user has chosen one.

From: http://trentrichardson.com/examples/timepicker/

Upvotes: 0

Bardo
Bardo

Reputation: 2523

Usually datepickers are associated to a textbox element. Try modifying the value of that element to have the date (usually today date) at 00:00.

Upvotes: 1

Related Questions