2

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...

SeventySix
  • 39
  • 2
  • 5
  • I'd guess it's a default behavior to prevent invalid dates from being entered (thus saving some lines of client-side validation). Isn't there a FAQ or something on the developer's page? – Fabrício Matté May 31 '12 at 04:53
  • I have looked everywhere, I dont want it to set it by default as the event (db record) might then be saved with the wrong dates by mistake... – SeventySix May 31 '12 at 04:59
  • And when i test the pickers examples on his site, they dont do it... – SeventySix May 31 '12 at 05:00
  • You're talking about this [jQuery UI addon](http://trentrichardson.com/examples/timepicker/) right? Maybe remove some/comment all of those parameters and check if the behavior is still the same. – Fabrício Matté May 31 '12 at 05:03
  • Yes thats the one,Ive tried even just with a blank function call like $(elem).datetimepicker(); and it still does it... – SeventySix May 31 '12 at 05:13

1 Answers1

0

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);
                    }
     });
BraveNewMath
  • 8,090
  • 5
  • 46
  • 51