jQuery Mobile and loading additional scripts is killing me. I've reviewed their documentation and I understand that their AJAX model causes some complexity, I've gotten some help from here to apply the info, but I still can't get everything to work consistently. Here's an example:
I have a page with 2 form fields, one for date and one for time. I am calling the jQuery UI Datepicker on the date field and a 3rd party Timepicker on the time field (this timepicker). If I access the page directly or do a refresh, both run just fine. But if I navigate to the page from elsewhere, only the datepicker runs. They are both linked in my document head and both called on the page with pageinit. Why does one work but not the other?
Head:
<!DOCTYPE html>
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Test Site</title>
<!-- Make it Mobile friendly -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="cleartype" content="on">
<!-- Stylesheets -->
<link rel="stylesheet" href="_css/normalize.css" />
<link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" rel="stylesheet">
<link rel="stylesheet" href="_css/jquery.mobile.structure-1.3.1.css" />
<link rel="stylesheet" href="_css/red_variant/red_variant.css" />
<link href="_libraries/jquery-ui-timepicker-0.3.2/jquery.ui.timepicker.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="_css/foundation.css" />
<link rel="stylesheet" href="_css/main.css" />
<!-- jQuery Including UI and Mobile -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" type="text/javascript"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js" type="text/javascript"></script>
<script src="_libraries/jquery-ui-timepicker-0.3.2/jquery.ui.timepicker.js" type="text/javascript"></script>
</head>
Form in question:
<form>
<label for="addAgendaDate" class="ui-hidden-accessible">Date:</label>
<input name="addAgendaDate" id="addAgendaDate" placeholder="Date" value="" type="text">
<label for="addAgendaTime" class="ui-hidden-accessible">Time:</label>
<input name="addAgendaTime" id="addAgendaTime" placeholder="Time" value="" type="text">
</form>
<script>
$(document).on('pageinit', function(){
$( "#addAgendaTime" ).timepicker({
showPeriod: true,
showLeadingZero: true
});
});
$(document).on('pageinit', function(){
$( "#addAgendaDate" ).datepicker();
});
</script>
What am I missing that causes both to work on normal page load but only one to work on jQuery Mobile AJAX loading?
Resolved! It took a month, but I finally wrapped my head around this. Gajotres and Kevin B were instrumental in getting me to understand the underlying script use issues, but each of my script problems ended up having different additional problems:
- The date and time picker inconsistency below was actually due to a CSS issue with z-index. Time picker was popping and working fine script-wise, but for some reason jQueryUI was setting its z-index inline to zero, which put it behind the mobile page overlay. CSS override (had to do an !important) fixed that.
- Had an issue with jQuery Countdown which was an ID duplicate issue since I had a PHP include pulling the same footer into each page. Changed to class to resolve.