So first let me start by saying I am new to jQuery mobile / any type of mobile dev. However I am building an app using Icenium which uses Phonegap. My app works fairly nicely but there are two big things I can't figure out.
- How to interact with the enter button i.e. fire the click handler like for my button.
- How to higlight all the text when the user clicks into the text box. So they don't have to use the keypads back key.
I have tried googling various terms but can't seem to find anything. The problem is you put the word jQuery in anything and the results are insane.
Here is my HTML.
<body>
<div data-role="page" id="home">
<div data-role="header">
<div id='SearchInput'>
<label for="txtSearchTerm">Search For a Session</label>
<input type="text" id="txtSearchTerm" value="" />
<input type="button" id="btnFilterSessions" value="Filter Sessions" />
<span id="sessionCount"></span>
</div>
</div>
<div data-role="content">
<ul id="sessionsList"></ul>
</div>
<div data-role="footer" data-position="fixed" data-id="oneFooter">
<span class="footerText">@r0k3t</span>
</div>
</div>
Here is my complete JS.
document.addEventListener("deviceready", onDeviceReady, false);
var codeMashApp = {};
function listSessions(sessions) {
$("#sessionsList").empty();
sessions.each(function() {
var title = $(this).find('Title').text();
var uri = $(this).find('URI').text();
$("#sessionsList").append("<li class='sessionTitle'><a href='#detailsPage' id='" + uri + "' data-transition='slide'>" + title + "</a></li>");
});
$("#sessionCount").text("Number of sessions: " + sessions.length);
}
function onDeviceReady() {
$.ajax({
type: "GET",
url: "http://rest.codemash.org/api/sessions",
data: "{}",
success: function(d) {
codeMashApp.rootElement = d.documentElement;
var sessions = $(codeMashApp.rootElement).find("Session");
listSessions(sessions);
}
});
$("#btnFilterSessions").click(searchSessions);
}
function searchSessions() {
var searchTerm = $("#txtSearchTerm").val();
if (searchTerm) {
var sessions = $(codeMashApp.rootElement).find("Title:contains(" + searchTerm + ")").parent();
listSessions(sessions);
} else {
reloadAllSessions()
}
}
function reloadAllSessions() {
var sessions = $(codeMashApp.rootElement).find("Session");
listSessions(sessions);
}