Datepicker update dates according to return of an ajax

Asked

Viewed 87 times

0

I want to display a calendar with only some dates enabled, I make an ajax request that returns me an array with the dates I want to enable, the function I have today is similar to this example here at the Fiddle, only the array values *availableDates * needs to be passed in the Ajax request, below this my code.

//Função para modificar a agenda de acordo com o profissional
    $("#listaProfissionais").on('click', 'li a', function () {
        var id = $(this).attr('id');
        $.get("Agendamento/AgendaProfissional", { idFuncionario: id }, function (data) {

            availableDates = data;
            $("#calendario").css('display', 'block');
        });
    });


    $(function () {
        $("#calendario").datepicker({
            showOtherMonths: true,
            selectOtherMonths: true,
            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: 'Proximo',
            prevText: 'Anterior',
            minDate: 0,
            beforeShowDay: available
        });
    });


    var availableDates;
    function available(date) {
        dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
        if ($.inArray(dmy, availableDates) != -1) {
            return [true, "", "Available"];
        } else {
            return [false, "", "unAvailable"];
        }
    }
  • include Html to your question

  • @Leandroangelo managed to solve, the dates that the request was returning was separated by bar '"/" and the function was dealing with tracinho "-"

  • So I think it would be a case of closing that question

No answers

Browser other questions tagged

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