facebook

Canno Update checkbox on/off within multipage widget: CLOSED

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #336481 Reply

    hefferan
    Member

    Hello. 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.

    #336522 Reply

    hefferan
    Member

    The 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.

    #336524 Reply

    Hi,

    Thanks for following up sharing your solution. I’ve marked thread as closed.

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: Canno Update checkbox on/off within multipage widget: CLOSED

You must be logged in to post in the forum log in