JS help with bootstrap-datetimepicker

Status
Not open for further replies.

neilhwatson

Ars Scholae Palatinae
1,236
Greetings,

I'm inexperienced with javascript and could use some help. I have installed the css and js files, and inserted the relevant parts in HTML. Problems:

* The date does not end up in the form field (id timestamp).
* The widget does not hide; it is always on.

Code:
               <label for="timestamp" class="col-sm-2 control-label">Timestamp to search for</label>
               <div class="col-sm-4">
                  <div class="input-append date" id="datetimepicker">
                     <input type="text" class="form-control input-append date" id="timestamp">
                     <span class="add-on glyphicon glyphicon-calendar"></span>
                  </div>
               </div>

<script type="text/javascript">
  $(function() {
    $('#datetimepicker').datetimepicker({
      format: 'yyyy-mm-dd hh:ii:ss',
      pickerPosition: 'top-right',
    });
  });
</script>

https://github.com/smalot/bootstrap-datetimepicker
 

technophile

Ars Legatus Legionis
23,768
I haven't used it, but your markup doesn't seem to match the docs; your <input> tag shouldn't have the "input-append" or "date" classes:
Code:
<div class="input-append date" id="datetimepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
    <input class="span2" size="16" type="text" value="12-02-2012" />
    <span class="add-on"><i class="icon-th"></i></span>
</div>
You also aren't closing the input tag (if you're in quirks mode this doesn't matter, but it is good practice regardless).

I would also suggest checking the dev tools console to see if there are any exceptions or error messages.
 

krimhorn

Ars Legatus Legionis
39,865
Do you have the full bootstrap css installed or just the components that you want? If the latter, do you have components generated from dropdowns.less and sprites.less?

Typically when I have a problem with a component like this (whether it's add-on or built-in) I copy an example whole-hog just to see if it's my environment or some quirk of my use. Often going to jsfiddle or plunkr to get a barebones setup working.

In this case I think technophile's got it. I expect that the datepicker js is getting confused between your div and input both having the input-append and date classes. js derived from (or working with) Bootstrap's code often uses child and/or class selectors to identify where to put new elements.
 
Status
Not open for further replies.