jquery mobile $.mobile.showpageloadingmsg() is not working - jquery-mobile

I wish to show loading message during page transition in jQM and backbone. But the showPageLoadingMeassage isnt working.
Following is my code:
collection.js
findById : function(artistId, page, limit, sort) {
$.mobile.showPageLoadingMsg('a', 'Loading......', false);
var self = this;
if (limit == undefined) {
limit = 10;
}
$.mobile.showPageLoadingMsg('a', 'Loading......', false);
console.log("hello");
$.ajax({
type: "GET",
url: siteURL + 'artists/artist_detail/artist_id' + artistId + '.json',
}).done(function(msg) {
var response = JSON.parse(msg);
if (response.status == true) {
var dataArray = response.data;
console.log(dataArray);
self.reset(dataArray);
if (self.length > 0) {
$.mobile.hidePageLoadingMsg();
}
//return dataArray;
} $.mobile.showPageLoadingMsg($.mobile.pageLoadErrorMessageTheme, 'Sorry! No records found', true);
setTimeout(function() {
$.mobile.hidePageLoadingMsg();
}, 1500);
}
});
}
where am i getting wrong?
edited:
it works when for search page:
... findByTitle : function(keyword, genre, language, page, limit, sort, collection, fan, featured) {
//~ console.log(page);
var self = this;
if (limit == undefined) {
limit = 10;
}
$.mobile.showPageLoadingMsg('a', 'Searching......', false);
$.ajax({....

found the answer on stackoverflow itself- jQuery Mobile - Problems getting showPageLoadingMsg to work with pagebeforeshow or pagebeforeceate.
It says that sometimes jQM doesn't adds the ui-loading class to the body so we have to do it manually.
$('body').addClass('ui-loading');
$.mobile.showPageLoadingMsg('a', 'Searching......', false);
and while hiding the loading msg:
setTimeout(function() {
$('body').removeClass('ui-loading'); //remove class
$.mobile.hidePageLoadingMsg();
}, 1000);

This function was also deprecated and in the current versions is not at all.

Related

JQuery Mobile 1.4.2 - Showing Popup on Page Load

I am trying to show a popup when a page loads. I have a generic popup embedded in each page that should be shown if there are data in the popup itself. Here is the code I'm trying to use:
$(function() { // initial page load
$(document).on("pagechange",
function(event) {
var pageId = $(document).pagecontainer( "getActivePage" )[0].id;
displayMessages(pageId);
});
});
}
I've looked at every other sample I've seen on StackOverflow, but none of them seem to work. The error I'm getting is:
Error: cannot call methods on popup prior to initialization;
attempted to call method "open".
So, when can I call popup("open") on a popup?
EDIT TO INCLUDE displayMessage FUNCTION
function displayMessages(pageId) {
pageId = pageId || $("body").pagecontainer( "getActivePage" )[0].id;
try {
var errCount = parseInt( $(jq(pageId + ".errorCount")).val() );
if ( !isNaN(errCount) && errCount )
{
$( jq(pageId + ".errors") ).popup( "open" );
}
else if ( $(jq(pageId + ".message")).text() != "" )
{
$( jq(pageId + ".message") ).popup( "open" );
}
} catch (e) {
alert(e);
}
}

jQuery Mobile swipe navigation exception

I have a series of pages inside one document, I navigate from page to page making use of swipe in touch devices.
What I dont know how to do, is to stop the swipe event once I reach certain page id.
This is the code I am using form my navigation:
$('div.ui-page').live("swipeleft", function(){
var nextpage = $(this).next('div[data-role="page"]');
if (nextpage.length > 0) {
$.mobile.changePage(nextpage, "slide", false, true);
}
});
$('div.ui-page').live("swiperight", function(){
var prevpage = $(this).prev('div[data-role="page"]');
if (prevpage.length > 0) {
$.mobile.changePage(prevpage, {transition: "slide",
reverse: true}, true, true);
}
});
I am using JQM 1.3
Thank you for your help
Here's a working example: http://jsfiddle.net/Gajotres/GXex5/
$(document).off('swipeleft').on('swipeleft', '[data-role="page"]', function(event){
if($(this).attr('id') == 'article2') {
event.preventDefault();
return false;
}
var nextpage = $.mobile.activePage.next('[data-role="page"]');
// swipe using id of next page if exists
if (nextpage.length > 0) {
$.mobile.changePage(nextpage, {transition: "slide", reverse: false}, true, true);
}
event.handled = true;
});
$(document).off('swiperight').on('swiperight', '[data-role="page"]', function(event){
var prevpage = $(this).prev('[data-role="page"]');
if (prevpage.length > 0) {
$.mobile.changePage(prevpage, {transition: "slide", reverse: true}, true, true);
}
event.handled = true;
});
Basically all you need is this code:
if($(this).attr('id') == 'article2') {
event.preventDefault();
return false;
}
This code will check if some page has a certain name and if it is so it will prevent default action (event). Also dont forget to pass a event object in your code, so
change this:
$('div.ui-page').live("swiperight", function(){
to this:
$('div.ui-page').live("swiperight", function(event){
Use the below to define next and previous page ID, if it equals to the page you don't want to show, do nothing.
var DoNothing = 'DoNothing';
// fetch ID of next page in DOM
var nextpage = $.mobile.activePage.next('[data-role=page]')[0].id;
// fetch ID of previous page in DOM
var prevpage = $.mobile.activePage.prev('[data-role=page]')[0].id;
// logic
if(nextpage == DoNothing || prevpage == DoNothing) {
// Do nothing!
}

jQuery autocomplete completely unresponsive

This is my first time really delving into jQuery with my ASP MVC3 intranet app. I need the autocomplete to be able to reference a list of items from a database. I followed the tutorial found here and thought "ok, that looks easy"... and now after implementing the code and researching other methods and bashing my head against the keyboard for at least four hours I'm not anywhere closer to making this work that before I wrote the code.
Here is the code from the view, w/the library declarations as well. FYI - I am taking over this project, so all the other javascript/Ajax you see was written by someone else with more experience than me. I put all the code in this section just in case something else is getting in the way.
<link href="../../Content/jquery-ui-1.9.2.custom.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.8.3.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#BankName").autocomplete({
source: '#Url.Action("GetBanks", "AgentTransmission")',
minLength: 1
});
$(function () {
$("#drpProducerType").change(function () {
var value = $(this).val();
if (value == "SoleProprietor") {
$("#Role").val(value);
$('#DSSfields').removeClass('noSee');
$('#DSSfields').addClass('seeMe');
//alert("Role must be set to \"Sole Proprietor\" as well. Monet will do this for you!");
}
else {
//TO DO: add role stuff here as well
$('#DSSfields').removeClass('seeMe');
$('#DSSfields').addClass('noSee');
}
});
$("#Role").change(function () {
var value = $(this).val();
if (value == "SoleProprietor") {
$("#drpProducerType").val(value);
alert("Producer Type changed to \"Sole Proprietor\" as well");
}
});
});
function ChangeChannel() {
//this function called if Market Segment changes, to update the channel
var pendistcode = document.getElementById('Pendist');
if (pendistcode == null) alert('Error: Cannot find Market Segment control');
$.ajax({
type: 'POST',
url: '/AgentTransmission/GetChannel/',
data: { pendist: pendistcode.value },
success: function (data) {
// alert("success: " + data);
$('#channelName').html(data);
$('#Channel').val(data);
},
error: function (data) {
alert("failure to obtain Channel name");
}
});
CheckTerritory('channel');
} //end ChangeChannel
function CheckTerritory(category) {
//this function called when changes happen that could change the territory (inddist)
//if the channel changed, or the alignment indicator, update the Territory
if ((category == "channel") | (category == "align")) UpdateTerritory();
//only trigger if the state or zip changed on the aligned address
if ((category == "L") && ($('#AlignmentL').attr('checked'))) UpdateTerritory();
if ((category == "M") && ($('#AlignmentM').attr('checked'))) UpdateTerritory();
} //end CheckTerritory
function UpdateTerritory() {
var i = $('#INDDist').val();
var p = $('#Pendist').val();
// alert(":" + i + ":" + p + ":");
//if ((i == "") || (p == "")) return;
if (p == "") return;
if ($('#INDDist').val() == "864") {
$('#INDDist').val("701");
}
else {
if ($('#INDDist').val() == "") {
$('#INDDist').val("864");
}
}
} //end UpdateTerritory
function MoreCompanies(row) {
//if the user clicks on the plus sign, add more company rows
if (row == '3') {
$('#plus2').html(' ');
$('#row3').removeClass('noSee');
$('#row3').addClass('seeMe');
}
if (row == '4') {
$('#plus3').html(' ');
$('#row4').removeClass('noSee');
$('#row4').addClass('seeMe');
}
if (row == '5') {
$('#plus4').html(' ');
$('#row5').removeClass('noSee');
$('#row5').addClass('seeMe');
}
} //end MoreCompanies
function CompanyFields() {
} //end CompanyFields
function ShowHideTerritory() {
alert('sunshine');
} //end ShowHideTerritory
</script>
The text box the autocomplete is supposed to work on
<div class="M-editor-label">
Bank\Agency Name
</div>
<div class="M-editor-field">
#Html.TextBoxFor(model => model.BankName, new { id = "BankName" })
#Html.ValidationMessageFor(model => model.BankName)
</div>
and here is the GetBanks method from the controller. I've set a breakpoint at the first line of this method and I've never been able to get it to hit.
//GET
public JsonResult GetBanks(string search)
{
var banks = from c in db.BankListMaster.Where(n => n.BankName.Contains(search))
select c.BankName;
banks = banks.Distinct();
return Json(banks, JsonRequestBehavior.AllowGet);
}
EDIT
If I replace the current .autocomplete code with the code suggested by this method instead , I get the following error in Chrome's debugger:
Uncaught Error: cannot call methods on autocomplete prior to initialization; attempted to call method '/AgentTransmission/GetBanks'
Here's the new code, I put it in the exact same spot as what I was previously using:
$(document).ready( function() {
$('#BankName').autocomplete('#Url.Action("GetBanks", "AgentTransmission")', {
dataType: 'json',
parse: function(data) {
var rows = new Array();
for(var i=0; i<data.length; i++){
rows[i] = { data:data[i], value:data[i].BankName };
}
return rows;
},
formatItem: function(row, i, n) {
return row.BankName + ' - ' + row.Description;
},
width: 300,
mustMatch: true,
});
});
I added an extra set of closing brackets to the autocomplete which cleared this up. The widget functions properly now.
$(function () {
$("#BankNameAuto").autocomplete({
source: '#Url.Action("GetBanks", "AgentTransmission")',
minLength: 1
});
});

TipTip only working on second hover after ajaxpost

Situation:
My tooltips show up on my page. Opening my fancybox works. Doing the ajax post from that fancybox works.
But my tooltips don't work in that fancybox. And they don't work after my ajax post.
I tried to reinitialize TipTip with the callbacks of fancybox.
EDIT
Title changes
So I found a way to let it run on the second hover after post but not on first hover.
I also found some explanations here but it still didn't fix my problem. Probably doing it wrong.
EDIT 2
Tootip in fancybox working use afterShow only.
Changes
added this in $(function () { so that it calls this function instead of initTipTip.
$(".tooltip").live('mouseover', function () {
$(this).tipTip();
});
Code of my function that does the post thing and closes my fancybox.
var reservation = MakeReservation();
var oldDateSplit = $("#resDate").val().split('/');
var newDateSplit = $("#dateEditReservation").val().split('/');
var oldDate = new Date(oldDateSplit[2], oldDateSplit[1] - 1, oldDateSplit[0]);
var newDate = new Date(newDateSplit[2], newDateSplit[1] - 1, newDateSplit[0]);
var time = $("#txtTime");
$.ajax({
url: ResolveUrl('~/Reservation/CheckSettings'),
data: "JSONString=" + reservation + "&hasJavaScriptMethod=" + true
}).done(function (data) {
if (data.length == 0 || oldDate.getTime() == newDate.getTime()) {
$.fancybox.close();
var id = $("#reservationId").val();
$("#reservationList").load(ResolveUrl('~/Reservation/reservationList',
function () { initTipTip(); }));
$("#reservationDetail").load(ResolveUrl('~/Reservation/DetailInfo',
function () { initTipTip(); }), { reservationId: id });
$("#reservationList").on("hover", " .tooltip", function () { $(this).tipTip(); });
}
else {
$(".errorDiv").removeClass("hidden");
$(".errorDiv").html(data);
$(".btnReservations").removeAttr('disabled');
}
});
NEW
$(".tooltip").live('mouseover', function () {
$(this).tipTip();
});
}
Still the same as before the edit.
Code initialization for TipTip
function initTipTip () {
$(".tooltip").tipTip();
}
Code of fancybox
function openFancy() {
$("a.inline").fancybox({
'type': 'ajax',
'afterShow': function () {
return initTipTip();
}
});
$("a.inlineBlockedDate").fancybox({
'type': 'ajax',
'ajax': { cache: false },
'afterShow': function () {
return initTipTip();
}
});
}
I found the solution for this.
So I used my .live in $(function(){ like in my question but I did not use ".tooltip" here but the table itself. I also use initTipTip here instead of $(this).tipTip();
So this solves the Tooltip from TipTip.
Explanation: This is because the tooltip.live only gets triggered on first hover and not when the table 'refreshes'. So now you add that event on that refresh of the table
Correct me if I'm wrong here.
So no need for any other .tiptip stuff or InitTipTip then in $(function(){
$("#reservationList").live('mouseover', function () {
initTipTip();
});
I hope your problem gets solved with this question.

jQuery Dialog leaving page on getScript() call

I have the following jQueryUI Dialog element.. I'm trying to make an AJAX call to populate the form when it launches.. I'm also using Ajax to load the actual form..
Problem happens when the populateForm method is invoked..
The Dialog disappears and the browser leaves my page when the $.getScript method is invoked..
any ideas?
I'm stuck!
DIALOG
$('#highValueSurvey').dialog({
autoOpen: false,
modal: true,
width: 900,
resizable: false,
open: function(event, ui) {
$("#highValueSurvey").load('/longstoryshort/forms/high.html');
$("#highValueSurvey").dialog('option', 'position', 'center');
populateForm('#FY12-Q1-AM-ALL-ECMC-VML-ProfilingForm');
},
buttons: {
'Submit': function() {
var path = $(this).data('link').href; // Get the stored result
doAjaxPost('#FY12-Q1-AM-ALL-ECMC-VML-ProfilingForm');
setCookie(highValueCookieName, -1, 1000);
window.location.href = path;
}
}
});
CLICK EVENT
$("a.clickHighValueAsset").click(function(e) {
cookie_value = getCookie(highValueCookieName);
if (cookie_value != -1) {
e.preventDefault();
e.stopImmediatePropagation();
$("#highValueSurvey")
.data('link', this)// bind the url from the HREF to the dialog UI for redirect later
.dialog('open');
}
else {
return true;
}
});
POPULATE METHOD
function populateForm(formName) {
if (typeof eMail != 'undefined') {
elqServlet = window.location.protocol + '//' + window.location.host + '/longstoryshort/forms/lookup.jsp?email=';
$.getScript(elqServlet + eMail, function() {
$(':input', '#' + formName).each(function() {
var field = '#' + this.name + '';
$(field).val(GetElqContentPersonalizationValue(this.name));
});
});
}
}
Wrap the populateForm() which is async.. And then call the window.href redirect within it's success callback!
Example:
'Submit': function() {
$.ajax({
type: "POST",
async: true,
url: $("#FY12-Q1-AM-ALL-ECMC-VML-ProfilingForm").attr('action'),
data: $("#FY12-Q1-AM-ALL-ECMC-VML-ProfilingForm").serialize()
});
setCookie(highValueCookieName, -1, 1000);
$(":button:contains('Submit')").hide();
$("#highValueSurvey").load('/longstoryshort/forms/confirmation.html');
$("#highValueSurvey").dialog({
close: function() {
var path = $(this).data('link').href; // Get the stored result
window.location.href = path;
}
});
}

Resources