views:

35

answers:

1

Hi. I created a calendar with Datepicker, but recently I'm having some trouble with it. The default date is always selected during months. I.e. today is Sep 15th, when I navigate to other months, the 15th day of that month is select as well (as if it's the defaultDate).

As they say, "A picture is worth a thousand words":

http://img405.imageshack.us/img405/6348/calendarmo.png

Translation: Outubro -> October, Novembro -> November, ... Dom -> Sunday, Seg -> Monday, ...

That's my code for this datePicker:

$("#datepicker").datepicker({
    //Espaço de tempo para reserva de horário
    minDate:'0',
    maxDate: '31/12/2010',
    defaultDate: null,
    //Controle de acesso
    beforeShowDay: verificaData,
    onSelect: retornaTexto
});

This is an auxiliary function that I use:

function verificaData(date) {
   if (date.getDay() != 0) {
    for (var i = 0; i < datasDisponiveis.length; i++) {
     if (date.toString() == new Date(datasDisponiveis[i]).toString()) {
      return [true,''];
     }
    }
    return [false,''];
   }
   return [false,''];
  }

Basicaly it verify an array checking if the date is currently available.

That's about it. I can't see where the error is, can you guys help me?

Thanks in advance!

EDIT:

I think I'm using the latest Datepicker version, this are my includes:

<script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
<script src="jquery.min.js"></script>
<script src="jquery-ui.min.js"></script>
<script type="text/javascript" src="jquery.ui.datepicker-pt-BR.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"&gt;&lt;/script&gt;
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
A: 

This is what I use for my datepicker (jQuery UI Datepicker 1.7.2) :

untillcal.datepicker({
    inline: true,
    minDate: minUntillDate,
    maxDate: maxUntillDate, 
    numberOfMonths: 1, 
    dateFormat: 'dd/mm/yy',
    hideIfNoPrevNext: true,
    showOn: 'button',
    constrainInput : true,
    beforeShowDay: function(date) {
        if($.isArray(excludedDays)){
            if($.inArray(Date.parse(date), excludedDays) > -1)
                return [false,''];
        }
        return [true,''];
    },
    buttonImage : '../../images/calendar.gif'
});

But this will just select the date specified and won't select the same day on the next month.

Just wanted to share, I know it doesn't solve your problem.

Peter
Thanks for sharing it! I'll try to adapt here. The problem that mine used to work, I don't know what happened. :(
dccarmo