facebook

Populating ComboBox from LocalStorage

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

    BrianJaydien
    Member

    Hello Everyone,

    I’m new to MobiOne and programming iPhone apps in general, but I really love this program.

    My question is as follows:

    I am gathering user data such as name, email, gender, height weight, etc… & storing it in LocalStorage. I have that part down and it seems to be working. I then recall that data when the document loads and populate the text fields with the appropriate localstorage data.

    Stores the data:

    localStorage.setItem('LSName',$('#m1-Daily_Meal_Tracker-name').val());
    var namefield = $('#m1-locstorage-LSName').val();

    Recalls The data:

    $('#m1-Daily_Meal_Tracker-name').val(localStorage.getItem('LSName'));

    My problem is that the Combo Boxes do not show the value the that is being pulled from localstorage until you click on it, then you can see the proper selection with a check next to it.

    Is there any way to have it show the selection with the check next to it when the document is loaded. It’s a little confusion the way it is right now as the user won’t think the data has been saved until they click the actual combobox.

    Also, is localstorage data saved when the app process is removed from memory or the phone is rebooted?

    Thanks.
    Brian

    #337804 Reply

    Stu Wade
    Member

    Seems we have the same problem.
    My post is here http://www.genuitec.com/support-genuitec/viewtopic.php?f=8&t=5380
    I don’t have an answer yet, but I think we should keep an eye on both topics.

    #337806 Reply

    BrianJaydien
    Member

    Yeah seems as though it is something silly that we’re missing.

    In HTML, you can programmaticaly (Not sure how to spell that) tell the browser to show that a particular item is selected based on Database query results, etc… This is sort of the same concept, but looks like the selected value that is preset in the designer fdr the combobox is over-riding the value set by the Javascript code.

    The joys of programming.

    -Brian

    #337909 Reply

    BrianJaydien
    Member

    Anyone???

    #337910 Reply

    Hi Brian,

    Please take a look at this post with a similar question, you should just adapt a little your code to load the content of localStorage.

    http://www.genuitec.com/support-genuitec/viewtopic.php?f=9&t=4323

    #337930 Reply

    Stu Wade
    Member

    Hi Octavio,

    Thanks for the above. Sadly I have tried changing the DOM reference to the combo box name as you suggested and still no joy. My original query is linked in my post above in this thread.

    #337933 Reply

    BrianJaydien
    Member

    Same here. That had no effect.

    -Brian

    #337941 Reply

    Brandon
    Member

    Try this. Will populate the combo box using the key as the combo text

    Attachments:
    You must be logged in to view attached files.
    #337957 Reply

    Stu Wade
    Member

    Thanks CincyPlanet – but again no joy …

    Your example gives a compiler error
    “TypeError: Result of expression ‘lCombo’ [null] is not an object.”

    Sadly, my knowledge of JavaScript is not upto debugging this. Were it to work, your approach seems to be just the ticket for my App. Is the use of LocalStorage required actually required for this approach to work, or just to make it fit Brian’s situation better?

    #337958 Reply

    Brandon
    Member

    Try installing the latest Dev build from here:
    https://docs.google.com/file/d/0B2UbQ9Htq1UWWjVUX3RnbzVkQUU/edit

    Ive noticed the changes they have made have been affecting a lot of my samples for older versions.

    #339662 Reply

    Publio Decio
    Member

    @CincyPlanet

    Do you have any idea of how to change the labels of the combobox at runtime?

    For example in the case of APP multi language.

    The example you entered does not work, i’ve the 2.5 dev-5.
    I entered my code 4 example

    Thank You
    Alessandro

    function Combo(container_id, comboData)
    {
    var lCombo = $(‘ac-mtchome-hidden-select-‘ + container_id);
    lCombo.remove(0);
    lCombo.length = 0
    lCombo.selectedIndex = 0;
    var noOfOptions = comboData.length;
    for (var i = 0; i < noOfOptions; i ++ )
    {
    var oOption = document.createElement(“option”);
    oOption.text = comboData[i];//item;
    oOption.value = i;
    lCombo.add(oOption);
    }
    }

    #339733 Reply

    Hi Alessandro,

    Next example provided by dev team should be helpful for you.

    Attachments:
    You must be logged in to view attached files.
    #339744 Reply

    Publio Decio
    Member

    Perfect !!!

    Thank you

    Alessandro

    #342317 Reply

    egroj90
    Member

    Hi, i saw the example, but how can i achive the same thing on pageload, how can i populate the combobox on page load?

    Hugo Silva

    #342356 Reply

    Hi Hugo,

    If you want the combobox is populated when the app is lanched you should put the code that populate the combobox in the phoneui.documentReadyhandler function that it’s on your www-appName/appName_custom.js file. If you want to do it when a page is loaded you ought to put the code in the prePageTransition function. Hope this make sense.

Viewing 15 posts - 1 through 15 (of 15 total)
Reply To: Populating ComboBox from LocalStorage

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