I'm using a model to load in another page. On the page should be a date picker but it's not showing up. If I just load the page without using the model the date picker works fine.
I realise that because the element I'm trying to bind to doesn't exist yet I need some extra Jquery to bind the .datetimepicker to the element once it's loaded.
$("#EditContentLog1bt").live("click", function () {
alert("test1");
$("#datepick").ready(function () {
alert("test2");
$("#datepick").datetimepicker({
pickTime: false,
format: "dd/MM/yyyy",
});
});
});
I've tried using .load rather than .ready but with .load I don't get to the second alert. With .ready I get to the second alert but the datepicker still doesn't work.
Html:
<div class="control-group">
<label for="followup" class="control-label">Date</label>
<div class="controls">
<div id="datepick" class="input-append date">
<input type="text" name="date" value="<?php echo date('d-m-Y', strtotime($contactLog->follow_up_date)); ?>">
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
</span>
</div>
</div>
</div>
<div class="control-group">
<label for="followup" class="control-label">Time</label>
<div class="controls">
<div id="timepick" class="input-append date">
<input type="text" name="time" value="<?php echo date('H:i', strtotime($contactLog->follow_up_date)); ?>">
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
</span>
</div>
</div>
</div>
This doesn't seem to be a z-index issue as I've got the datepicker working in another model but only by using .click rather than .load/.ready.
This is now the model gets called:
<a data-toggle="modal" data-target="#myModal" id="EditContentLog1bt" href="<?php echo site_url('manager/editContactLog/' . base64_encode($this->encrypt->encode($log->id))); ?>" class="btn btn-primary contactLog">Edit</a>
And here's the html for the model:
<div id="myModalform" style="width:700px; margin-left:-380px;" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>