How to view several pre-selected dates in the jquery datepicker ui?

Asked

Viewed 505 times

0

My code does not show the dates selected in the calendar ,see I have an array of dates but 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>

1 answer

1

Notice the dates you have on array are in format yy/mm/dd and in the code you are asking datepicker to format with dd/mm/yy.

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

jsFiddle: https://jsfiddle.net/usrbo7fe/

Notes:

  • Notice that you are looking for an ID that starts with large letter D. Checks that the ID in HTML is the same.
  • notes that the blocking dates are in May, you have to move forward to see them (because it’s April)

I hope I’ve helped!

  • 1

    am now receiving dates in this format and be giving error ["2015-04-10T00:00:00","2015-04-11T00:00:00"]

  • @Hansmiller you mean the dates within var array are in this format and not in the format you put in the question?

  • yes! would have to format them to stay in this module?

  • @Hansmiller yes, does so: https://jsfiddle.net/usrbo7fe/1/

  • face generates datepicker but does not highlight the dates on the calendar

  • @Hansmiller ok, so you can be clearer: where it comes from array? this is what you want: https://jsfiddle.net/usrbo7fe/2/ ?

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.