3

enter image description here

I'm working with http://eonasdan.github.io/bootstrap-datetimepicker/. If you open https://jsfiddle.net/Eonasdan/0Ltv25o8/ you see that the initial date is empty and only fills on clicking on the widget (also see screenshot ). This is the behaviour I want.

In my setup the default is set to the current date.

</div>

    <script type="text/javascript">
        $(function () {
            $('#datetimepicker5').datetimepicker({
                enabledHours: [ 12,19,20,21 ],
                stepping:15,
                sideBySide: true,
                defaultDate:false
            });
        });
    </script>

I've tried defaultDate:false, but the current date still shows up. How can I fix this?

user1592380
  • 34,265
  • 92
  • 284
  • 515

3 Answers3

1

if you are still struggling for the answer then, just try your own method by using the below code. However, I will explain my scenario

<input type='text' class="form-control" readonly id='datetimepicker4' />
<script>
$(document).ready(function() {
    var date = new Date();
    var year = date.getFullYear();
    $('#datetimepicker4').datetimepicker({
        viewMode: 'years',
        format: 'DD/MM/YYYY',
        ignoreReadonly: true,
        defaultDate: {year: year}
     });
     $('#datetimepicker4').val("");
)};
</script>

In the above code, I'm using "readonly" in the input tag and then in the script using ignoreReadOnly to true, this will ignore the readonly given in input tag by datetimepicker, however, the user cannot type anything yet can only select the date. Specifically, in the above case I'm using for the current year and set to default date, this will set the input tag with some default value, in my case Jan 1 of current year so to remove it just used a tweak in jquery to reinitialize the #datetimepicker4 id with an empty value. This will set the empty value at web page loading. Again, I know this is not a permanent solution however for those who can't or not interested to tweak js file, can also use this method. Feel free to query any doubts. Thank you

0

I tried it and succeeded.

$(function () {
    $('#datetimepicker5').datetimepicker({
       enabledHours: [ 12,19,20,21 ],
       stepping:15,
       sideBySide: true
    }).datetimepicker('setDate', null);
});
poppies
  • 142
  • 6
0

I used a datetimepicker config:

let datetimepicker_config{
     useCurrent: false
}

$("#myinput").datetimepicker(datetimepicker_config);

it worked for me.

DPalharini
  • 413
  • 6
  • 16