This works:
$(document).ready(function ($) {
$('#datetimepicker1').datetimepicker();
when I have
<p>Date: <input type="text" id="datetimepicker1"></p>
Placed on my main form. As it works it suggests to me all the references are ok.
However when I launch a modal:
$(function () {
$('#rotasModal').on("show.bs.modal", function (e) {
which JavaScript appends
<input type="text" id="datetimepicker2">
<input type="text" id="datetimepicker3">...
x number of these to a form (each having a unique id) I get Uncaught TypeError: $(...).datetimepicker is not a function when calling:
$('#datetimepicker2').datetimepicker();
Even when I defer that and try it in the debug console, the same error. It seems to be related to the modal and not the fact that the components are generated when the modal is shown (as I've also tried creating them directly in the modal's form and not generating them on the fly).
Any ideas what could be causing this please?
Edit: As I've been asked to be more specific re. the code, I have included the references in the layouts/app.blade.php:
<script language="JavaScript"
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script language="JavaScript"
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<script src="{{asset('js/jquery-ui-timepicker-addon.js')}}"></script>
<script src="{{asset('js/jquery-ui-sliderAccess.js')}}"></script>
At the top of by create.blade I have:
extends('layouts.app')
@section('content')
<div class="container">
Further down I have the modal declared:
div class="modal fade" id="rotasModal"
tabindex="-1" role="dialog"
aria-labelledby="rotasModalLabel">
If I do a view source I see:
<!DOCTYPE html>
<script language="JavaScript"
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script language="JavaScript"
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<script src="http://oc.com:8888/oc/public/js/jquery-ui-timepicker-addon.js"></script>
<script src="http://oc.com:8888/oc/public/js/jquery-ui-sliderAccess.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.1/bootstrap3-typeahead.min.js"></script>
<link href="http://oc.com:8888/oc/public/css/jquery-ui-timepicker-addon.css">
<!-- Styles -->
<link href="http://oc.com:8888/oc/public/css/app.css" rel="stylesheet">
<link href="http://oc.com:8888/oc/public/css/ocm.css" rel="stylesheet">
You can ignore my statement about creating dynamically (actually from the data in an ajax success) because I tried commenting it out and hardcoding a control.
It still stands that the control will only work if I call .datetimepicker() from $(document).ready(.... .
I don't know how the plugin code is not referenced. If it is the case then how is it available in the .ready() and why then if I call $('#datetimepicker1').datetimepicker(); from the Chrome console I get the same error?
Thanks for your persistence in helping me.
$('.datetimepicker')then reference desired dom