1

In this fiddle inside the view appointments tab,there is add timing button.When I click on the button then a new row gets added.Now when I click on the calender icon then a pop comes up which shows the current hour and minutes.But I want it to show 00:00. Can any body please tell me how to do?

I have tried to modify the setDate method inside the bootstrap date time picker source code

setLocalDate: function (localDate) {
    if (!localDate) 
        this.setValue(null);
    else 
        this.setValue(Date.UTC(localDate.getFullYear(), localDate.getMonth(), localDate.getDate(), localDate.getHours(), localDate.getMinutes(), localDate.getSeconds(), localDate.getMilliseconds()))
},

to

setLocalDate: function (localDate) {
    if (!localDate) 
        this.setValue(null);
    else 
        this.setValue(00, 00, 00, 00,00, 00, 00))
},

but it did not work.Please anybody tell me what else do I have to change

Roman C
  • 49,761
  • 33
  • 66
  • 176
SpringLearner
  • 13,738
  • 20
  • 78
  • 116
  • @RobG thanks,I will try and let you know – SpringLearner May 19 '14 at 05:45
  • @RobG I tried your way but it still shows the current time – SpringLearner May 19 '14 at 05:50
  • I wouldn't go messing with the library anyway. According the to the (extremely minimal) [documentation](http://www.eyecon.ro/bootstrap-datepicker/), you should be using `.datepicker('setValue', value)` where *value* can be "a string in the specified format or a Date object". – RobG May 19 '14 at 06:13

1 Answers1

2

As @RobG already said, you can simply set the value in the initialization routine

ko.bindingHandlers.datepicker1 = {
    init: function (element, valueAccessor, allBindingsAccessor) {
        $(function () {
            $(element).parent().datetimepicker({
                pickDate: false,
                pickSeconds: false,
                minuteStep: 10
            });

            $(element).parent().datetimepicker('setValue', '00:00');
        });

// ...

See updated JSFiddle

Update:

If you want 00:00 as default value only, you must pick the value from the valueAccessor first and set 00:00, if the value is undefined

init: function (element, valueAccessor, allBindingsAccessor) {
    $(function () {
        $(element).parent().datetimepicker({
            pickDate: false,
            pickSeconds: false,
            minuteStep: 10
        });

        var accessor = valueAccessor();
        var val = ko.unwrap(accessor) || '00:00';
        $(element).parent().datetimepicker('setValue', val);
    });

// ...

See JSFiddle

Update:

Unfortunately, I cannot find any documentation about version 2.2.0. Testing, if the accessor is a function, seems to work

var val = valueAccessor();
if (typeof(val) == 'function')
    val = val();

$(element).parent().datetimepicker('setValue', val || '00:00');

Updated JSFiddle

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198