datetimepicker sets date to todays date on when cl

2019-03-03 02:30发布

问题:

I have searched high and low for the answer to this issue, but no luck so now I have to ask...

I have the datetimepicker from Trent Richardson, and for some reason with very minimal options set, it automatically sets the date field to todays date when i click outside without selecting a date.

Anyone have an idea whats going on?

This is my code:

$('input.datetime').datetimepicker({
        ampm: true,
        timeFormat: 'hh:mm tt',
        addSliderAccess: true,
        sliderAccessArgs: { touchonly: false },
     });

Appreciate all the help I can get, its causing some confusion for my staff using the application...

回答1:

i searched high and low too, but after putting a few debug messages, the answer was obvious. What I noticed is that the onClose method has a "value" parameter which has the actual date which you select OR if you select nothing, it has the original value from your textbox. Set it as the value of the inputbox and walaaaa! problem solved.

If you don't do this, the current date will replace your original date when you just want to close the datetimepicker.

$('input.datetime').datetimepicker({
        ampm: true,
        timeFormat: 'hh:mm tt',
        addSliderAccess: true,
        sliderAccessArgs: { touchonly: false },
        onClose: function (value) {
                        $('input.datetime').val(value);
                    }
     });