Datepicker does not open when loading Ajax into a Bootstrap 4 modal

Asked

Viewed 193 times

0

I need to open a calendar in an input that is in the file uploaded by Ajax.

How can I call the plugin Datepicker when a Ajax in a modal Bootstrap?

I have these codes:

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title" id="myModalLabel">Exames - 

       <?
       echo $nome;
       ?>

          </h4>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
      </div>

    </div>
  </div>
</div>

Button to open the Modal

<button type="button" class="btn btn-success openBtn" data-id ='<? echo $row["id"]?>'>Ver Exame</button>

Ajax carrying with Modal

$('.openBtn').on('click',function(){
var myBookId = $(this).data('id');
$('.modal-body').load('getContent_exames.php?id='+myBookId,function(){
$('#myModal').modal({show:true});
});
});

getContent_exames.php (file that Ajax loads)

    <div class="form-group col-md-12">
<label for="data1_inicio">Data de Pagamento</label>   
<input type="text" id="data1_inicio" value="<? echo $cmsData['data']?>" name="data1_inicio" autocomplete="off" class="form-control data" value="">  
</div>  

    <script>
    $( function() {
        $( "#data1_inicio_exames" ).datepicker();
        $( "#data1_inicio" ).datepicker();
        $( "#data2_final" ).datepicker();
      } );
    </script>

1 answer

0


Hello, add this code instead of the $( "#data1_inicio" ).datepicker();.

  $(function () {
        window.prettyPrint && prettyPrint();
        $('#data1_inicio').datepicker({
            format: 'dd-mm-yyyy',
            language: 'pt-BR'
        });
    });

Browser other questions tagged

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