xdan / datetimepicker

jQuery Plugin Date and Time Picker
https://xdsoft.net/jqplugins/datetimepicker/
MIT License
3.5k stars 1.52k forks source link

Change date when blur #502

Open adfec opened 8 years ago

adfec commented 8 years ago

When the component has another date format instead of "d/m/Y" and you click outside the element, it replace the date you previously selected with the current date.

I got the issue with this declaration:

$( '.datetimepicker' ).datetimepicker( { timepicker: false, format: 'Ymd' } );

adfec commented 8 years ago

Need to say, I used moment.js as says the documentation, the code above is wrong

albertleao commented 8 years ago

Same issue here

iamfinky commented 7 years ago

@adfec The documentation here isn't really very clear on (a) how this actually works and (b) how you then reformat the date to pass back to the server-side. Would you mind posting a clear example?

adfec commented 7 years ago

@iamfinky I solved it this way:


$( '.datetimepicker' ).datetimepicker( {timepicker:false,format:'Y/m/d'} ).on( 'blur', function(){
        $( this ).val( moment( $( this ).val() ).format('YYYYMMDD') );
});