5

I am using javascript calender in my magento site.I am using this calendar for date of delivery.

  1. First when user selects previous date from current date then it should be disabled.
  2. Is there any way to set the delivery date as +4 day, that means on the calendar, if the client buy today it can only choose the delivery date after 4 days from the calendar

Its an urgent requirement. Please suggest me some solution.

2
<script type="text/javascript">
  Calendar.setup({
  inputField : 'cal_date',
  range: [Date(),2014],
  ifFormat : '%m/%e/%y',
  button : 'date_from_trig',
  align : 'Bl',
  singleClick : true,
      weekNumbers: false,
  disableFunc: function(date) {
      var today = new Date();
              var dd = today.getDate();
              var mm = today.getMonth();

       return date.getDate() < dd ;         
        // Sunday is 0, Monday is 1, and so on
        /* var today = new Date();
              var dd = today.getDate();
              var mm = today.getMonth()+1; //January is 0!

              var yyyy = today.getFullYear();

              return today;*/

    }
  });
</script>

Use this code to disable previous dates.

| improve this answer | |
2
<script type="text/javascript">
 Calendar.setup({
        inputField : '_dob',
        ifFormat : '%m/%e/%y',
        button : '_dob_trig',
        align : 'Bl',
        singleClick : true,
        disableFunc: function(date) {
          var now= new Date();
        if(date.getFullYear()<now.getFullYear())
        {
            return true;
        }
        if(date.getFullYear()==now.getFullYear())
        {
            if(date.getMonth()<now.getMonth())
            {
                return true;
            }
        }
        if(date.getMonth()==now.getMonth())
        {
            if(date.getDate()<now.getDate())
            {
                return true;
            }
        }
    },
    });
</script>

from

https://stackoverflow.com/questions/14117215/how-to-disable-previous-days-in-default-dhtml-calendar

| improve this answer | |
2

Adding the following to your calander setup will disable all dates that are not 4 days in the future.

disableFunc : function(date) {
    var today = new Date();
    today.setDate(today.getDate()+4);
    return (date <= today);
}

Though I would still validate on the php side as the user could work around the calendar input type.

| improve this answer | |
2

Now We will DISABLE past Dates. Solution:

app/code/core/Mage/Core/Block/Html/Date.php

(it is advisable to add custom calendar template, as in any upgrade you will lose your modifications)

Use the folowing to disable the previous dates:

//<![CDATA[
           var calendarSetupObject = {
                inputField  : "' . $this->getId() . '",
                ifFormat    : "' . $displayFormat . '",
                showsTime   : "' . ($this->getTime() ? 'true' : 'false') . '",
                button      : "' . $this->getId() . '_trig",
                align       : "Bl",
                singleClick : true,
                disableFunc: function(date)  {
                    var now= new Date();
                    if(date.getFullYear()   <   now.getFullYear())  { return true; }
                    if(date.getFullYear()   ==  now.getFullYear())  { if(date.getMonth()    <   now.getMonth()) { return true; } }
                    if(date.getMonth()      ==  now.getMonth())     { if(date.getDate()     <   now.getDate())  { return true; } }
                },
            }';
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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