Load datepicker into modal

Asked

Viewed 685 times

2

Good morning.

I’m not able to load the datepicker inside a modal called via ajax, someone would have an example of code?

MODAL:

<div class="modal fade" id="modalaltera" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">Recuperar Chave de Acesso</h4>
        </div>

        <div class="modal-body">
            <form method="POST" id="formulario" name='formulario' action="">
            <label>Dia</label>
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-calendar"></i></div>
                            <input type="text" name='dia2' class="form-control" id="dia2" placeholder="Selecione a Data" required   >
                        </div>

                        <br>


                        <label for="sel1">Horario</label>
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-clock-o"></i></div>
                            <select class="form-control" id="hora" name="hora" >

                                <option value="" >---</option>

                            </select>
                        </div><br><br> 
            </form>
        </div>

        <div class="modal-footer">


            <script src="<?= base_url() ?>assets/js/input-mask/jquery.inputmask.js"></script>
            <button type="button" class="btn btn-default form_submit" onclick="enviarpass(recemail.value)">ENVIAR PALAVRA CHAVE</button>
        </div>
    </div>
</div>

JS

function modalaltera(){
    $('#modalaltera').modal('show');
    }

$('#dia2').datepicker({
                    format: "dd/mm/yyyy",
                    language: 'pt-BR'
                });

Thank you

  • You can show the code you have and it doesn’t work?

1 answer

1

Try this solution:

<input type="text" value="" class="form-control" placeholder="00/00/0000" id="dia2" />

Javascript:

$("#dia2").datepicker({
    dateFormat: 'dd/mm/yy',
    dayNames: ['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado', 'Domingo'],
    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']
});
  • He complains that datepicker is not a function - (index):318 Uncaught Typeerror: $(...). datepicker is not a Function

  • you put the datepicker reference?

  • you put this? <link href="~/Content/jquery-ui.css" rel="stylesheet" />

  • Put but did not work, it seems that the modal is not 'inheriting' the scripts

  • where you are called the modal?

  • I have a button in the.php query view when clicked opens a modal with some data and a change button, this change button should open another modal to select the date, the script is in another view called footer.php

  • try to put the reference in the same view

  • The button has the onclick event for Function: Function modalaltera(){ $('#modalaltera'). modal('show'); }

  • It didn’t work, but stopped complaining that the datepicker doesn’t exist

  • What mistake you made?

  • No error, it makes sense to be something related to css?

  • unlikely, you have already tried to run this code in the browser console or already given debug?

  • I discovered the mistake, was a div that was closing before the modal rs... Thanks for the support!

Show 8 more comments

Browser other questions tagged

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