Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Calendar javascript bug when current date is disabled? 
 
mpikounis
Member
 
Total Posts:  67
Joined:  2009-01-26
Athens, Greece
 

Hi!

I am using the javascript calendar that comes with magento and I think I have run into a bug. I have a function that determines whether a date should be selectable or disabled. It all works great unless the current date (today, or the value of the input field associated with the calendar) should be disabled. If this is the case, the calendar blocks and you cannot select any date.

I am pretty sure I am not doing anything wrong, so I was wondering if this is a known issue and if so, whether there is a recommended solution?

Thanks,
Michael

 
Magento Community Magento Community
Magento Community
Magento Community
 
jmcdog
Jr. Member
 
Total Posts:  20
Joined:  2008-05-08
 

I’m having the same issue.

From the docs for jscalendar-1.0 I’ve added a function to Calendar.setup using the dateStatusFunc parameter. I can disable dates. But if today is disabled on the initial popup—clicking on a day will not select it. If I advance a few months I can then get a day to select.

I have it so on the first popup of the calendar, today will be highlighted and is clickable. Then the next time the calendar is opened today is disabled and not clickable.

I think it may have something to do with a function that highlights the current day??

I can see that js/calendar/calendar.js has several modifications for Magento to support local time settings.

I can take the original code from jscalendar-1.0 website and disable today’s date without any issues.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jmcdog
Jr. Member
 
Total Posts:  20
Joined:  2008-05-08
 

I’m still working on this one. But I figured out if I populate the input box with a day in the future (next available delivery day) then the calendar works. I would rather not do this because I want the customer to get an error message if they don’t select a delivery date.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Keith Moon
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2009-03-08
London
 

What’s the java function to disable certain weekdays?

 
Magento Community Magento Community
Magento Community
Magento Community
 
strangetxino
Jr. Member
 
Total Posts:  1
Joined:  2010-03-21
 

Hi guys,

First post in the community, bit lazy, but very helpful forum and people wink

Well after fighting against the calendar, goingt to Dynarch, trying to implement other calendars, blah blah blah… I’ve found a temporary solution to the disabled day and not being able to select a day.

Basically what I’ve done is go to calendar.js, located in your Magento installation folder (under js/calendar/calendar.js), and made a small change under line 648, changing:

var newdate false;

to

var newdate true;

With that and some tweakings on my Calendar.setup function I’ve been able to control my calendar disabled days, and this little bug, I’ve hardcoded the Javascript functions to my wrapper.phtml (under app/design/frontend/default/default/template/catalog/product/view/options/wrapper.phtml), probably not the best solution, but works perfectly for me.

I think the best way to do this though, would be to create an external Javascript, and a small block of code and attach it later to the date.phtml (under app/design/frontend/default/default/template/catalog/product/view/options/type/date.phtml), as I said before, I’m a bit lazy, and did it the ‘dirty’ way.

In case you want to know how to add Javascript to you Magento themes, check this article http://www.magento.cc/how-to-add-or-remove-javascript-css-on-magento.html, or even this thread within this community http://www.magentocommerce.com/boards/viewthread/6935/, and to add the chunck of code to date.phtml, just check the code, study it, and make it dynamic, in my case I used this function to disable dates (Note: the function can be placed anywhere, even in an external Javascript, best practice I believe, but the Claendar.setup must go after the date input text, as it will call it to attach the calendar to it, and if it doesn’t exist it can’t setup the calendar, that or window.onload, or dom:loaded with Prototype, what ever you preffer):

<script type="text/javascript">
    
//<![CDATA[
    
var today_date =  new Date();
    var 
tomorrow_date =  new Date();
    
tomorrow_date.setDate(today_date.getDate()+1);
    
tomorrow_date.setHours(0,0,0);
    var 
disabled_date [];
    
disabled_date[2010] 
    0
:[1,6],
    
1:[],
    
2:[],
    
3:[2],
    
4:[1],
    
5:[],
    
6:[],
    
7:[15],
    
8:[],
    
9:[12],
    
10:[1],
    
11:[6,8,25]};
    
disabled_date[2011] 
    0
:[1,6],
    
1:[],
    
2:[],
    
3:[2],
    
4:[1],
    
5:[],
    
6:[],
    
7:[15],
    
8:[],
    
9:[12],
    
10:[1],
    
11:[6,8,25]};
    var 
weekend_days [0,1,6];
    var 
starting_date= new Date(2010,9,19);
    var 
ending_date= new Date(2011,6,1);
    
    function 
disabledDate(dateymd{
        
if (date <= today_date || date <starting_date || date >= ending_date)
            return 
true;
        for (var 
i in weekend_days
            if (
weekend_days[i] == date.getDay()) 
                return 
true;
        if (
disabled_date[y])
        
{                    
            
var no_delivery disabled_date[y][m];
            if (
no_delivery){
                
for (var i in no_delivery
                    if (
no_delivery[i] == d
                        return 
true;
            
}
        }
        
return false
    
};
    
//]]>
</script>

And my Calendar.setup looks something like this (Note: check your generated Javascript code, as I’ve not included these properties for demonstration purposes, inputField, ifFormat, button, align, which are necessary):

Calendar.setup({
    
...
    
electricfalse,
    
dateStatusFunc disabledDate,
    
range[2010,2011],
    
weekNumbersfalse,
    
singleClick true
}
);

Well I hope it all makes sense, and someone can use this info.

Best regards smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Allysin
Sr. Member
 
Avatar
Total Posts:  215
Joined:  2008-04-03
 

I can’t understand the post above (guess I’m just a ‘dumb blond’)

Would anyone please please write a step-by-step easy to follow instructions on how to do this?

All I’ve been trying to do is - I have the calendar but have not been able to block out dates. And I really need to be able to do that....

Please help red face

 
Magento Community Magento Community
Magento Community
Magento Community
 
bzydura2010
Jr. Member
 
Total Posts:  9
Joined:  2012-02-02
 

Hi,I am new on magento
I am using a free shipping method in Magento 1.5

Is there any way to set the delivery date to:  +1 day, that means in the calendar the client can only star choosing to deliver only from next day.
for example: if a client buy today , the delivery date on the calendar display only the date from tomorow.

thank you in advance for the answer.

 
Magento Community Magento Community
Magento Community
Magento Community
 
kelvinkyaw
Jr. Member
 
Total Posts:  3
Joined:  2013-01-29
Myanmar [Burma], Yangon
 

How this?

Calendar.setup({
        inputField 
\'_dob\',
        
ifFormat \'%d/%m/%y\',
        
button \'_dob_trig\',
        
align \'Bl\',
        
singleClick true,
        
disableFunc: function(date{
              
var today = new Date();
              var 
dd today.getDate();
              var 
mm today.getMonth()+1//January is 0!

              
var yyyy today.getFullYear();
              if(
dd<10){dd=\'0\'+dd} if(mm<10){mm=\'0\'+mm} today mm+\'/\'+dd+\'/\'+yyyy;
              return 
today;
        
}
 }
);
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top