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.
Try to change your selector to this:
$('#finalModal .datepicker').datepicker({
format: "dd.mm.yyyy"
})
This fixed it for me.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With