I'm using this datetime picker for Bootstrap 4 https://tempusdominus.github.io/bootstrap-4/
The plugin works just fine if the input is blank at load. However, I have an Edit form that has already a value but the datepicker is removing the value at page load.
<div class="container">
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<input class="form-control datetimepicker-input" data-target="#Entry_EntryDate" data-toggle="datetimepicker" data-val="true" data-val-date="The field Event Date must be a date." data-val-required="The Event Date field is required." id="Entry_EntryDate" type="datetime" value="2017-10-25 10:17 AM" />
</div>
</div>
</div>
</div>
and default js
$(function() {
$('#Entry_EntryDate').datetimepicker();
});
Here is the JsFiddle
I forked the recommended jsfiddle so I'm sure I have all the correct needed dependencies.
I tried changing locales, changing formats but no luck.
Set datetimepicker FORMAT property to custom. set CUSTOM FORMAT property to empty string " ". set its TAG to 0 by default.
It is by default set to new Date() . You just need to set property valueDefault={null} and the DatePicker will be blank.
Bootstrap 5 DateTimepicker. DateTimepicker is a form that adds the function of selecting date and time without the necessity of using custom JavaScript code.
When you are initializing datetimepicker it is clearing the value by default, so in order to keep the value, you will need to remember the value $('#Entry_EntryDate').val()
convert it to date object and pass it to timepicker on initialization:
and default js
$(function() {
var date = moment($('#Entry_EntryDate').val(), 'YYYY-MM-DD hh:mm a').toDate();
$('#Entry_EntryDate').datetimepicker({date:date});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With