How to view multiple preselected dates in datepicker jquery ui?

0

My code does not show the dates selected in the calendar, see I have an array of dates but it does not show.

<script src="~/Scripts/jquery.js"></script>
<script src="~/Scripts/jquery-ui.js"></script>
<link href="~/Content/jquery-ui.css" rel="stylesheet" />
<script type="text/javascript">
    var $j = jQuery.noConflict();
    var array = ["2015/05/03", "2015/05/13", "2015/05/23"];

    $j("#Data").datepicker({
        dateFormat: 'dd/mm/yy',
        dayNames: ['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'],
        dayNamesMin: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S', 'D'],
        dayNamesShort: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb', 'Dom'],
        monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
        monthNamesShort: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'],
        nextText: 'Próximo',
        prevText: 'Anterior',
        beforeShowDay: function(date) {
            if ($j.inArray($j.datepicker.formatDate('dd/mm/yy', date), array) > -1) {
                return [false, "", "Booked out"];
            } else {
                return [true, '', "available"];
            }
        }
    });
</script>
    
asked by anonymous 08.04.2015 / 03:42

1 answer

1

Notice that the dates you have in array are in the format yy/mm/dd and in the code you're prompting the datepicker to format with dd/mm/yy .

Switch to formatDate('yy/mm/dd', date) and it will work.

jsFiddle: link

Notes:

  • Notice that you are looking for an ID that begins with large D . Verify that the ID in the HTML is the same.
  • Note that the dates you block are in May, you have to walk forward to see them (as we are in April)

I hope I have helped!

    
08.04.2015 / 08:23