-1

I'm using the bootstrap datetime picker, the documentation of which can be found here: https://eonasdan.github.io/bootstrap-datetimepicker/Options/

I'm trying to set the selected date to null. I'm able to blank out the date (i.e. 2/10/2019) within the input field, but when I click on the input field and the calendar opens, the old date is still selected in blue. WiThis is my code to de-select all dates within the calendar.

 $(document).ready(function() {

    $('.removedate').on('click', function(){

       $("#id_booking_date").val('') //this correctly removes date from input field

       $('.input-group').datetimepicker({
            date: new Date(null)
        });

}); 

This code isn't working. Do you know what I should try?

Thanks!

Jason Howard
  • 1,464
  • 1
  • 14
  • 43
  • can you please share your code with html – Asad Feb 05 '19 at 05:51
  • I'm just using the standard datetimepicker functionality. My html looks like the html on the examples on the front page of https://eonasdan.github.io/bootstrap-datetimepicker/Options/ – Jason Howard Feb 05 '19 at 05:54
  • Possible duplicate of [Clear the value in a datetimepicker field](https://stackoverflow.com/questions/32142432/clear-the-value-in-a-datetimepicker-field) – VincenzoC Feb 05 '19 at 08:52
  • Take a look at [this question](https://stackoverflow.com/q/43780734/4131048) too. – VincenzoC Feb 05 '19 at 08:53

2 Answers2

-1

Can you please try to use "useCurrent" option for this? Check it out here https://eonasdan.github.io/bootstrap-datetimepicker/Options/#usecurrent

Binal Gajjar
  • 322
  • 1
  • 6
  • No, that sets the selected date to current date. I want to remove the date selection from teh calendar. Thanks though! – Jason Howard Feb 05 '19 at 06:03
  • But If a false boolean is passed then no initialization happens on the input element. – Binal Gajjar Feb 05 '19 at 06:04
  • Correct. On the input element. As mentioned above, I've already got the input element covered. I want to remove the selected date in the widget. – Jason Howard Feb 05 '19 at 06:28
-1

Please try this, they have clearly mentioned here

Working example:

$('#datetimepicker4').datetimepicker({ 

       useCurrent: false,//  
 });
Nikhil G
  • 2,096
  • 14
  • 18
  • "If a false boolean is passed then no initialization happens on the input element." As mentioned, I've already set the input value to null. I'm looking to remove the selected date in the calendar widget. – Jason Howard Feb 05 '19 at 06:27
  • Did you checked after add this option. I have working demo in my local server and it removes the selected date in the calendar widget. – Nikhil G Feb 05 '19 at 06:50
  • I already have this permanently set as an attribute on the form field – Jason Howard Feb 05 '19 at 06:55