Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 2.53 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Datepicker - Using a default function with a custom function
  2. var $myBadDates = new Array (<?php foreach($aryDates as $disabledate) { echo " "$disabledate","; } echo " 1"; ?>); //Creates the array (The echo " 1"; is merely to close the array and will not affect the outcome
  3.        
  4. function checkAvailability(mydate)
  5.             {
  6.             var $return=true;
  7.             var $returnclass ="available";
  8.  
  9.             $checkdate = $.datepicker.formatDate('yy-mm-dd', mydate);
  10.             for(var i = 0; i < $myBadDates.length; i++)
  11.                 {    
  12.                if($myBadDates[i] == $checkdate)
  13.                     {
  14.                     $return = false;
  15.                     $returnclass= "unavailable";
  16.                     }
  17.                 }
  18.             return [$return,$returnclass];
  19.             }
  20.        
  21. $(function()
  22.             {
  23.             //To enable End Date picker only when Start Date has been chosen (And to disable all dates prior of said date)
  24.             var end = $('#enddate').datepicker( {numberOfMonths: 3, stepMonths: 3, beforeShowDay: checkAvailability,});
  25.        
  26. // Defining a function, because we're binding this to two different events
  27.             function enableEnd() {
  28.                 end.attr('disabled', !this.value.length) // Enable the end input element if the first one has anything in it
  29.                    .datepicker('option', 'minDate', this.value); // Set the minimum date to the date in the first input
  30.                 }
  31.             //End of function
  32.  
  33.             // Datepicker
  34.             $('#startdate').datepicker({
  35.                 numberOfMonths: 3,
  36.                 stepMonths: 3,
  37.                 beforeShowDay: checkAvailability,
  38.                 minDate: +1,
  39.                 onSelect: enableEnd // Call enableEnd when a date is selected in the first datepicker
  40.             }).bind('input', enableEnd); // Do the same when something is inputted by the user
  41.  
  42.             //hover states on the static widgets
  43.             $('#dialog_link, ul#icons li').hover(
  44.                 function() {$(this).toggleClass('ui-state-hover');}
  45.                 );          
  46.             });
  47.         //End of Function
  48.        
  49. function checkAvailability(d) {
  50.     if (
  51.         d.getDay() == 6 /* saturday */ ||
  52.         d.getDay() == 0 /* sunday */
  53.     ) {
  54.         return [false,'unavailable unavailable-cuz-its-weekend'];
  55.     }
  56.     $checkdate = $.datepicker.formatDate('yy-mm-dd', d);
  57.     for (var i = 0; i < $myBadDates.length; i++) {
  58.         if($myBadDates[i] == $checkdate)
  59.         {
  60.             return [false, "unavailable"];
  61.         }
  62.     }
  63.     return [true, "available"];
  64. }