title: Bootstrap datepicker with knockout.js databind
body: <p>This question is similar to <a href="https://stackoverflow.com/questions/6399078">knockoutjs databind with jquery-ui datepicker</a>, but instead of the jQueryUI datepicker, I would like to use one of the <a href="https://github.com/Aymkdn/Datepicker-for-Bootstrap" rel="nofollow noreferrer">Bootstrap datepickers</a>.</p>
  
  <p>The API for the Bootstrap datepicker is different from jquery-ui, and I am having some trouble wrapping my head around making it work with knockout.js. I have created <a href="http://jsfiddle.net/bmh_ca/Qehaj/3/" rel="nofollow noreferrer">a jsFiddle to try it out</a>.</p>
  
  <p>It seems like the Bootstrap datepicker could be much simpler to use because it does not independently store the date. However, I would like to know how whether the jsFiddle is the appropriate way to use the Bootstrap datepicker widget with knockout.js i.e.</p>
  
  <pre><code>ko.bindingHandlers.datepicker = {
      init: function(element, valueAccessor, allBindingsAccessor) {
        //initialize datepicker with some optional options
        var options = allBindingsAccessor().datepickerOptions || {};
        $(element).datepicker(options);
  
        ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
              $(element).datepicker("destroy");
          });
      },
      update: function(element, valueAccessor) {
      }
  };
  </code></pre>