Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: Cannot read property 'split' of undefined - bootstrap datepicker

i am using bootstrap datepicker for the input in bootstrap modal window. When I opened this windows for the first time, everything is ok and datepicker works fine. When I close this modal window and opened it again, my js console says Uncaught TypeError: Cannot read property 'split' of undefined

I'm loading form in modal window with ajax.

This is my modal window:

<div id="finalModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="myModalLabel">Final date</h3>
            </div>
            <div class="modal-body" id="finalModalBody">

            </div>
            <div class="modal-footer">
                <button id="finalSubmit" class="btn btn-success">Save</button>
            </div>

After loading this window, this script is started:

$('.datepicker').datepicker({
           format: "dd.mm.yyyy"
})

And this is my formin modal window:

<form>
<p><select onfocus="this.onmousewheel=function(){return false}" class="prereservationSelect" name="prereservation" id="frmfinalForm-prereservation"><option value="89">15. 7. 2014 - 19. 7. 2014</option><option value="0">second date</option></select></p>
<div id="otherDate" style="display: none">
    <p><strong><label for="frmfinalForm-otherDate">Zvolte jiný termín:</label></strong></p>
    <p style="float: left"><input type="text" class="datepicker text" name="otherDate" id="frmfinalForm-otherDate" value=""></p>
    <p style="margin-top: 15px; margin-left: 250px" id="date"></p>
</div>
</form>

Thanks for any advice.

like image 463
Lukeluha Avatar asked Jul 16 '14 12:07

Lukeluha


2 Answers

Try to change your selector to this:

$('#finalModal .datepicker').datepicker({
    format: "dd.mm.yyyy"
})

This fixed it for me.

like image 142
stef Avatar answered Oct 18 '22 00:10

stef


For me, the issue was that the method was called twice. Make sure that it's called only once, and you won't have this error

like image 3
Yishai Landau Avatar answered Oct 18 '22 02:10

Yishai Landau