From kodeboard, 4 Years ago, written in Plain Text.
Embed
  1. /**
  2.  * For the eternicode bootstrap-datepicker.js plugin
  3.  *
  4.  * This is for dependent date fields.  If you have 2 date fields,
  5.  * like a checkin / checkout field, you may have conditions that need
  6.  * the checkout field to re-render based on the date of the
  7.  * checkin datepicker.
  8.  *
  9.  */
  10. <script>
  11. var today = new Date();
  12.  
  13. $(document).ready(function() {
  14.  
  15.    var dp = $('#dp').datepicker({
  16.  
  17.    //format: 'mm-dd-yyyy',
  18.    beforeShowDay: function(date) {
  19.  
  20.      if(date.getDate() > 15 || date.getMonth() >= today.getMonth()+1) {
  21.        console.log("green: date:" + date);
  22.        return {enabled:true,classes:'green',tooltip:'Tooltip Info'}
  23.      }
  24.    }
  25.  }).on('show', function(e) {
  26.  
  27.     //this is the magic here.. forces the datepicker to run beforeShowDay()
  28.     //each time the calendar is displayed.
  29.     $(this).datepicker('update');
  30.  
  31.  });
  32. });
  33. </script>

You must login to reply or comment on this code.