tempusdominus / bootstrap-4

Tempus Dominus Bootstrap 4 Datetime Picker
https://getdatepicker.com/5-4/
MIT License
609 stars 238 forks source link

HTML text inputs don't include date from HTML value attribute or JavaScript date option #126

Open FlipperPA opened 6 years ago

FlipperPA commented 6 years ago

In the following repro, only the JavaScript date option is provided for start_date, and both the value HTML attribute and date JavaScript option are provided for end_date.

<input type="text" name="start_date" class="form-control datetimepicker-input" placeholder="Start Date" title="" data-toggle="datetimepicker" data-target="#id_start_date" id="id_start_date">
<script type="text/javascript">
    $(function () {
        $('#id_start_date').datetimepicker({"format": "YYYY-MM-DD", "date": "2018-05-29"});
    });
</script>

<input type="text" name="end_date" value="2018-05-29" class="form-control datetimepicker-input" placeholder="End Date" title="" data-toggle="datetimepicker" data-target="#id_end_date" id="id_end_date">
<script type="text/javascript">
    $(function () {
        $('#id_end_date').datetimepicker({"format": "YYYY-MM-DD", "date": "2018-05-29"});
    });
</script>

Thanks for the amazing work, I hope this is detailed enough.

chrisharney commented 6 years ago

I solved this issue by just setting the value after it is initiated.

        $('.datetimepicker-input').each(function() {
            var value = $(this).val();
            $(this).datetimepicker({
                format: 'YYYY-MM-DD',
                date: value
            });
            $(this).val(value);
        });
luisamajose commented 5 years ago

Thank you!!! after hours of searching