- This topic has 2 replies, 2 voices, and was last updated 11 years, 8 months ago by support-octavio.
-
AuthorPosts
-
hefferanMemberHello. I have been struggling with this for some time now and finally decided to request assistance. I have a multipage widget with three pages. The second page contains a bunch of settings. These include input text and checkbox (toggle). Note, that I am testing this as a native Android app, Android version 2.3.3 (kindle fire).
I have added this bit of code to ensure that everything is loaded before I start:
phoneui.documentReadyHandler = function() {
document.addEventListener(“deviceready”, onDeviceReady, false);
}and then:
function onDeviceReady() {
// Now safe to use the PhoneGap API
document.addEventListener(“pause”, onPause, false);
document.addEventListener(“resume”, onResume, false);
init();
}The onResume also calls the init() function. The init() function contains a series of methods similar to this one:
if(localStorage.getItem(“my.storage.key”) == null) {
// starting app for the first time, let’s set initial data values
localStorage.setItem(“my.storage.key”, false);
$(“#m1-sos-sendAlert input”).prop(‘checked’,false);
} else {
// set the checkbox toggle to the previously stored value
var storedAlertValue = localStorage.getItem(“my.storage.key”);
$(“#m1-sos-sendAlert input”).prop(‘checked’,storedAlertValue);}
However, calling alert($(“#m1-sos-sendAlert input”).prop(‘checked’)); returns UNDEFINED rather than the expect value of ‘false’. Further, when I tap on the “Settings” tab, my sendAlert check box is still turned on.
I have noticed that when I am on the settings page and clicked a “info” button which calls and alert($(“#m1-sos-sendAlert input”).prop(‘checked’)) the value is shown correctly (and no UNDEFINED message).
I’ve searched around and it seems that manipulating data which are hidden from view should be possible which leads me to believe that I have either missed something conceptually or I have just simply done something wrong.
Any assistance is greatly appreciated.
hefferanMemberThe reasaon alert($(“#m1-sos-sendAlert input”).prop(‘checked’)); would return UNDEFINED was because the storedAlertValue I retrieved from localStorage was evaluated as a string not a boolean. I ended up doing a check like :
if(val == false || val == ‘false’) {
$(“#m1-sos-sendAlerts input”).prop(‘checked’,false);
}
Then alert($(“#m1-sos-sendAlert input”).prop(‘checked’)); would show the proper value.
support-octavioMemberHi,
Thanks for following up sharing your solution. I’ve marked thread as closed.
-
AuthorPosts