Datepicker Do not select certain dates

Asked

Viewed 658 times

1

I’m unable to make this code work, I want some dates not selected in datepicker.

Now it is not working anymore, does not open the window to select the dates

someone can help me?

$().ready(function()
{


    var ranges = [{ start: moment(new Date('05/05/2016')).format("dd/mm/yy"), end: moment(new Date('15/05/2016')).format("dd/mm/yy") },
                  { start: moment(new Date('20/06/2016')).format("dd/mm/yy"), end: moment(new Date('26/06/2016')).format("dd/mm/yy") }];

    var dates = $("#dataInicio, #dataFinal")
                .datepicker({
                            dateFormat: 'dd/mm/yy',
                            changeMonth: false,
                            numberOfMonths: 2,
                            beforeShowDay: function(date) {
                                    $.each(ranges, function(index) {
                                    if (date >= ranges[index].start && date <= ranges[index].end)
                                    {
                                        return [true, ''];
                                    }
                                })return [false, ''];
                },

                minDate: ranges[0].start,
                maxDate: ranges[ranges.length - 1].end,          
                defaultDate: ranges[0].start,
                onSelect: function() {
                    $(this).focusin();
            }


    });

    //Date picked fim
});

1 answer

1

Try to recycle that code. I hope it helps:

//Validar datas:

//Quando abre o datapicker seleciona a menor data para ser o dia de hoje now().
var now = new Date(),
minDateJS = now.toISOString().substring(0,10);

//Seleciona a data de entrega do produto.
//Aplica a data now (hoje) para ser a menor data selecionavel para a entrega do produto
//Aplica a data de entrega do produto para ser a menor data possivel do evento  
$('#dt_entregaProd').datepicker({
    dateFormat: 'yy-mm-dd',
    changeMonth: true,
    changeYear: true,
    minDate: minDateJS,
    inline: true,         
    onClose: function( selectedDate ) {//Passa a data selecionada neste objeto para ser a menor data possivel para realizar o evento
      $( "#dt_Event" ).datepicker( "option", "minDate", selectedDate );
    }

});             


//Seleciona a data do evento.
//Evento bidirecional. Se a data do evento for selecionada primeiro, entã a data máxima de entrega do produto será limitada automaticamente
$('#dt_Event').datepicker({
    dateFormat: 'yy-mm-dd',
    changeMonth: true,
    changeYear: true,
    minDate: minDateJS,
    inline: true, 
    onClose: function( selectedDate ) {
      $( "#dt_entregaProd" ).datepicker( "option", "maxDate", selectedDate );
    }        
 });     
  • Good morning, You didn’t help me with that code.

Browser other questions tagged

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