facebook

Retain App Settings Upon Exit: CLOSED

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

    mreade
    Member

    Support

    How can one retain the app settings upon closing the app so the same settings can be used once the app is started another time.

    Thanks in advance.

    #333834 Reply

    Hi mreade,

    Can you tell me what settings are you referring? if you want to keep data for the next time that you open the app, you could use localStorage: http://www.genuitec.com/support-genuitec/viewtopic.php?f=14&t=2251

    #333839 Reply

    mreade
    Member

    Octavio,

    I have a combobox on page1 called (units) with two items (Imperial and metric) with Imperial being the first item on the list.

    If users were to select metric, I would like for app to start in the metric calculation mode
    , not imperial and/or vice versa.

    Thanks in advance.

    mreade

    #333884 Reply

    Hi mreade,

    You can save in localStorage the value of selected value in combobox in the onChange action with next snippet code:

    $('select[name="combobox1"] option[value="value5"]').attr('selected','selected')
    phoneui.preprocessDOM('#m1-combo_localStorage');

    Then in phoneui.readyHandler function use next code to retrieve the value saved in localStorage and update the combobox selected value:

    var cmbLastVal = localStorage.getItem("val");
      $('select[name="combobox1"] option[value="'+cmbLastVal+'"]').attr('selected','selected')
      phoneui.preprocessDOM('#m1-combo_localStorage');
    #333887 Reply

    mreade
    Member

    Thanks Octavio,

    I am currently away and will give this a try next week, then let you know how I make out.

    Thanks

    mreade

    #334241 Reply

    mreade
    Member

    Octavio,

    I am just returning from being on the road for a week and I am going to try to implement localstorage into my app.

    However, I do have a few questions about the code snippet you posted on this matter.

    IN the first code snippet you indicated a “value5”. I am not sure what you are referring to with this code? In my combo list I have two items such as:

    Label Value Selected

    US (Imperial) imperial Yes
    SI (Metric) metric No

    The name of my combo list on the frmMain.mobi page has an ID of “units.”

    I tried the code you provide and I was not able to restart the app with the last combobox selection.

    Any suggestions?

    Thanks

    mreade

    #334255 Reply

    Hi mreade,

    Seems that I goofed up with my copy/paste code when I did a quick design to achieve this request. My apologies.

    The code for the onclick change should be this:

    localStorage.setItem("val",$('select[name="combobox1"]').val());

    Note that “val” is the key for the saved value.

    That value will be pulled with the second code I posted last time:

    var cmbLastVal = localStorage.getItem("val");
      $('select[name="combobox1"] option[value="'+cmbLastVal+'"]').attr('selected','selected')
      phoneui.preprocessDOM('#m1-combo_localStorage');
    #334257 Reply

    mreade
    Member

    Thanks Octavio,

    I will give the a try and advise.

    mreade

    #334258 Reply

    mreade
    Member

    Octavio,

    OK, it seems as though the last code snippet you suggests will store the combolist’s last selection (i.e.: imperial, or metric)

    Although the app will start with the proper combolist value selected (checked), the combolist widget shows the first item on the list. For example,

    I have two items on the list:

    1. US (Imperial) (which has a value of “imperial”)
    2. SI (Metric) (which has a value of “metric”)

    Upon starting the app, the default “imperial” values is selected and the US (Imperial) is showing in the combolist widget.

    I’ve selected the “metric” value to continue with metric calculations. That works fine. I close the app on my iPhone and upon restarting the app, although “metric” was the last selected item on the combolist, the US (Imperial) is still showing upon startup. As I open the combolist the SI (Metric) is checked so it looks like the proper item (value) is stored locally.

    Question:

    How can i get the app to also show the proper combolist item upon startup. For example:

    if “imperial” is the localstored value, show US (Imperial) upon startup, or if “metric” is the localstored value, show SI (Metric) upon startup.

    I hope this makes sense.

    Thanks

    mreade

    #334330 Reply

    mreade
    Member

    Support,

    Any suggestions how i can get the app to show the proper combobox item upon startup after recalling the localstorage value?

    Thanks

    mreade

    #334477 Reply

    @mreade,

    Q: Did you put the code that I suggest you to use in phoneui.documentReadyHandler function?

    @support-octavio wrote:

    Then in phoneui.readyHandler function use next code to retrieve the value saved in localStorage and update the combobox selected value:

    var cmbLastVal = localStorage.getItem("val");
      $('select[name="combobox1"] option[value="'+cmbLastVal+'"]').attr('selected','selected')
      phoneui.preprocessDOM('#m1-combo_localStorage');

    In case you did and is not working, could you attach your .mobi file and custom.js to take a look?

    #334489 Reply

    mreade
    Member

    Thank you, I will email a zip file containing the information.

    mreade

    #334491 Reply

    mreade
    Member

    Support,

    I have just finished emailing you a zip file with the .mobi form and _custom.js script file.

    mreade

    #334537 Reply

    mreade
    Member

    Octavio,

    Your suggestion of making a slight code change in the preprocessDOM snippet to reflect the form name and not the code in your snippet has corrected the problem with the combobox list not showing the proper list item upon starting.

    Now, when the app starts, it does show the proper combolist item.

    Thanks, problem solved.

    mreade

    #334554 Reply

    Hi mreade,

    Glad to know that all is working fine. Thanks for your follow up. Thread Closed.

Viewing 15 posts - 1 through 15 (of 15 total)
Reply To: Retain App Settings Upon Exit: CLOSED

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