0

The following is a date picker code. Here Sunday & saturday is disabled.I tried a lot to enable sunday.What changes to do to enable only sunday as working day.

<script>
      (function ($) {
    var disabledDays = ["5-28-2012","7-4-2012","7-5-2012","7-6-2012","9-3-2012","9-17-2012","9-26-2012","11-22-2012","11-23-2012","12-25-2012","1-1-2013"];
    function nationalDays(date) {
      var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
      for (i = 0; i < disabledDays.length; i++) {
        if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1) {
          return [false];
        }
      }
      return [true];
    }
    function noWeekendsOrHolidays(date) {
      var noWeekend = jQuery.datepicker.noWeekends(date);
      return noWeekend[0] ? nationalDays(date) : noWeekend;
    }
    var fourWorkingDays = new Date();
    var adjustments = [0, 0, 2, 2, 2, 2, 1];
    fourWorkingDays.setDate(fourWorkingDays.getDate() + 1 + adjustments[fourWorkingDays.getDay()]);
    jQuery(document).ready(function() {
      jQuery('#cf3_field_10').datepicker({
        minDate: 0,
       //maxDate: new Date(2011, 11, 31),
        dateFormat: 'DD, MM, d, yy',
        constrainInput: true,
        beforeShowDay: noWeekendsOrHolidays
      });
      jQuery('#cf3_field_11').timepicker({
            showPeriod: true,
            onHourShow: OnHourShowCallback,
            onMinuteShow: OnMinuteShowCallback
    });
    function OnHourShowCallback(hour) {
        if ((hour > 18) || (hour < 9)) {
            return false; // not valid
        }
        return true; // valid
    }
    function OnMinuteShowCallback(hour, minute) {
        if ((hour == 18) && (minute >= 0)) { return false; } // not valid
        if ((hour == 9) && (minute < 30)) { return false; }   // not valid
        return true;  // valid
    }
    });
    })(jQuery);
      </script>

I just want to enable only sunday as working day which is disabled already Check www.jbediamonds.com/form.php , DATE section

1
  • is this complete JS of jst part of it?
    – KAsh
    Feb 1, 2013 at 9:41

3 Answers 3

1

you can try to add some date picking properties to your js like below:

selectable_days: [0, 1, 2, 3, 4, 5, 6],
  non_selectable: [],
  rec_non_selectable: [],
  start_of_week: 1,
  show_week: 0,
  select_week: 0,
  week_label: "",
  date_min: "",
  date_max: "",

or simplest way- use another jQuery DatePicker.

This one is much easy to implement and also to change properties.

1

this is the text box for date picker

<input id="txtDate" type="text" />

here is the function caller :

   $(function () {
    $('#txtDate').datepicker({
        beforeShowDay: disabledays
    });
});

here is the enable disable function:

   var unavailableDates = ["2013-3-31", "2013-3-24"];

function disabledays(date) {
    var ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
    if ($.inArray(ymd, unavailableDates) >= 0) {
        return [false, "", "Unavailable"];
    } else {
        //Show only sundays and thuersdays
        var day = date.getDay();
        return [(day == 0 || day == 1 || day == 4)]; // add here date you want to enable
    }
}
0

You're using jQuery.datepicker.noWeekends(date) which will disable both Saturday and Sunday.

Have a look here for how to disable only certain days: jquery ui date picker limit to Sundays

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.