Bring a pre-selected day with Datepicker BOOTSTRAP

Asked

Viewed 220 times

0

inserir a descrição da imagem aqui

in this calendar I want to pre-load it with the day 5 pre-selected(active).

the code that carries it is this:

$('#agenda_profissional_online').datepicker({
        format: "yyyy-mm-dd", 
        //este é dia 5(datas[0]) que vem do meu array do banco.
        startDate: datas[0],
        endDate: datas[datas.length-1],
        language: "pt-BR",
        height: "300px",
        datesDisabled: datas_desativadas
    }).on('changeDate', function(e) {
        $("#agendar").fadeOut(400);
        $('#loading-padrao').toggle();
        var agendaData = $('#agenda_profissional_online').datepicker('getDate');
        // agendaData = agendaData.toLocaleDateString("pt-BR");
        agendaData = moment(agendaData).format('YYYY-MM-DD');
        //SOLICITACAO RECUPERO A DATA CLICADA ENVIO PARA O FUNCOES.PHP COM DOIS PARAMETROS SOLICITACAO VIA GET E PICKERDATA VIA POST)
        $.ajax({type:"POST",data:{pickerData:agendaData},url: "funcoes/funcoes.php?solicitacao=HORAS_DISPONIVEIS", success: function(result){                        
            $('#loading-padrao').toggle();               
            var horarios_disponiveis= [];
            // alert(result);
            var horarios = JSON.parse(result);

            $.each(horarios, function (index, value) {
                var hora = value.replace(agendaData,"");
                hora =hora.replace(":00.000","");                    
                console.log(hora);
                horarios_disponiveis.push("<span class='badge hora_badge'>"+hora+"</span>");
            });     
            $("#horarios_agendamento").fadeOut(200,function(){
                $(this).html(horarios_disponiveis).fadeIn();  
            });
        }});
        pega_horario();            
    });

Resolution, enontrada(however bug) need ajdua to solve

 $('#agenda_profissional_online').datepicker({
        format: "yyyy-mm-dd",        
        startDate: datas[0],
        endDate: datas[datas.length-1],
        language: "pt-BR",
        height: "300px",
        datesDisabled: datas_desativadas,
        beforeShowDay: function(date){
                            var caseinicial = datas[0].substr(-1);
                            caseinicial = parseInt(caseinicial);
                            console.log(caseinicial);
                          if (date.getMonth() == (new Date()).getMonth())
                            switch (date.getDate()){
                              case caseinicial:
                                return  {
                                  // tooltip: 'Example tooltip',
                                  classes: 'active',                                      
                                };                                
                          }
                          var agendaData = moment(date).format('YYYY-MM-DD');
                          busca_monta_horario(agendaData);
                        }            
    }).on('changeDate', function(e) {
        $("#agendar").fadeOut(400);         
        var agendaData = $('#agenda_profissional_online').datepicker('getDate');
        // agendaData = agendaData.toLocaleDateString("pt-BR");
        agendaData = moment(agendaData).format('YYYY-MM-DD');
        //SOLICITACAO RECUPERO A DATA CLICADA ENVIO PARA O FUNCOES.PHP COM DOIS PARAMETROS SOLICITACAO VIA GET E PICKERDATA VIA POST)
        busca_monta_horario(agendaData);
        pega_horario('');            
    });
}

}

but now comes one selected, only when selects another, both are selected

inserir a descrição da imagem aqui

1 answer

0

For datepicker you have the option startDate, to initialize datepicker with a preset date just add it

$('#agenda_profissional_online').datepicker({
    format: "yyyy-mm-dd", 
    //este é dia 5(datas[0]) que vem do meu array do banco.
    startDate: datas[0],
    endDate: datas[datas.length-1],
    language: "pt-BR",
    height: "300px",
    datesDisabled: datas_desativadas,
    startDate:  new Date('2019-03-06')
});
  • hi, sorry I mislabeled is the DATE PICKER BOOTSTRAP

  • @Igorsilva I made the edits for the datepicker bootstrap

  • actually, did not give, it only left enabled, but not left with active

  • I got a resolution on the question, only I generated another bug, see if you can help me

Browser other questions tagged

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